In this tutorial, you will learn about C math library function cos() that computes the cosine.

cos() is the standard C math library function that is defined in math library math.h.
#include<math.h>
double cos( double x );
where,
x = angle in radians ( floating point value )
This function returns the cosine value of x that ranges in the interval [ -1, 1 ].
The return type is double.
/*Use of math library function cos()*/
#include<stdio.h>
#include<math.h>
#define PI 3.1415926
int main()
{
double x ;
x = 60;
//calculation of cosine
printf("\ncos( %.2lf ) = %.2lf \n", x, cos( (x * PI) / 180 ));
x = 180;
//calculation of cosine
printf("\ncos( %.2lf ) = %.2lf \n", x, cos( (x * PI) / 180 ));
return 0;
}
Output

Explanation
In the above program, we have calculated the cosine of x.
We have defined macro PI for representing the value of pi.
The input of cos( ) can be any value.