w3resource

C cos() function

C cos() function - arc cosine functions

Syntax:

double cos(double x)

The cos() function is used to calculate the cosine of x. The value x is expressed in radians. If x is too large, a partial loss of significance in the result might occur.

Parameters:

Name Description Required /Optional
x Represent an angle expressed in radians. Required

Return value from cos()

  • The function returns the cosine of x.

Example: cos() function

The following example shows the usage of cos() function.


#include <math.h>
#include <stdio.h>
 
int main(void)
{
   double x, y;
 
   x = 0;
   y = cos(x);
   printf("cos( %lf ) = %lf\n", x, y);
   x = 1;
   y = cos(x);
   printf("\ncos( %lf ) = %lf\n", x, y);
   x = 45;
   y = cos(x);
   printf("\ncos( %lf ) = %lf\n", x, y);
}

Output:

cos( 0.000000 ) = 1.000000

cos( 1.000000 ) = 0.540302

cos( 45.000000 ) = 0.525322 

C Programming Code Editor:

Previous C Programming: C atan2()
Next C Programming: C cosh()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming/math/c-cos.php