C Standard Library

C <math.h> - cos() Function



The C <math.h> cos() function returns trigonometric cosine of an angle (angle should be in radians). In the graph below, cos(x) vs x is plotted.

Cos Function

Syntax

double cos (double x);
float cosf (float x);
long double cosl (long double x);

Parameters

x Specify the angle in radian.

Return Value

Returns the trigonometric cosine of an angle.

Example:

In the example below, cos() function is used to find out the trigonometric cosine of an angle.

#include <stdio.h>
#include <math.h>
 
int main (){
  //M_PI - value of PI from math.h
  printf("%lf\n",cos(M_PI/6));  
  printf("%lf\n",cos(M_PI/4)); 
  printf("%lf\n",cos(M_PI/3)); 
  return 0;
}

The output of the above code will be:

0.866025
0.707107
0.500000

❮ C <math.h> Library