Home >>C Math Functions >C math cos() function

C math cos() function

C math cos() function

The C library function double cos(double x) is used to return the cosine of a radian angle x. It takes a single argument in radians and returns a value in type double in the range 1 to 1. This function is defined in <math.h> header file.

Syntax:
double cos(double x);

Parameters:

x − It is the floating point value representing an angle expressed in radians.

Here is an example of cos() function:

#include <stdio.h>
#include <math.h>
#define PI 3.14159265 
int main () 
{ 
double x, ret, val; 
x = 60.0; 
val = PI / 180.0; 
ret = cos( x*val ); 
printf("The cosine of %lf is %lf degrees\n", x, ret); 
return(0); 
}

Output:
The cosine of 60.000000 is 0.500000 degrees
Example-2

#include <stdio.h>
#include <math.h>
#define PI 3.14159265 
int main () 
{ 
double x, ret, val; 
x = 90.0; 
val = PI / 180.0; 
ret = cos( x*val ); 
printf("The cosine of %lf is %lf degrees\n", x, ret); 
return(0); 
}

Output:
The cosine of 90.000000 is 0.000000 degrees