Facebook Page Twitter Page LinkedIn Page
× C Standard Library


The C <math.h> cos() function is used to return trigonometric cosine of an angle (angle should be in radians).

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 below example, 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