Latest web development tutorials

C library functions - cos ()

C standard library - <math.h> C standard library - <math.h>

description

C library functionsdouble cos (double x) Returns the cosine of xradians.

statement

Here it is () statement cos function.

double cos(double x)

parameter

  • x - floating-point value represents an angle in radians.

return value

This function returns the cosine of x.

Examples

The following example demonstrates the cos () function is used.

#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("%lf 的余弦是 %lf 度\n", x, ret);
   
   x = 90.0;
   val = PI / 180.0;
   ret = cos( x*val );
   printf("%lf 的余弦是 %lf 度\n", x, ret);
   
   return(0);
}

Let's compile and run the above program, which will result in the following:

60.000000 的余弦是 0.500000 度
90.000000 的余弦是 0.000000 度

C standard library - <math.h> C standard library - <math.h>