Easy Tutorial
❮ C Examples Quadratic Roots C Exercise Example75 ❯

C Library Function - cos()

C Standard Library - <math.h>

Description

The C library function double cos(double x) returns the cosine of the radian angle x.

Declaration

Following is the declaration for the cos() function.

double cos(double x)

Parameters

Return Value

This function returns the cosine of x.

Example

The following example demonstrates the use of the cos() function.

#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("The cosine of %lf is %lf degrees\n", x, ret);

   x = 90.0;
   val = PI / 180.0;
   ret = cos( x*val );
   printf("The cosine of %lf is %lf degrees\n", x, ret);

   return(0);
}

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

The cosine of 60.000000 is 0.500000 degrees
The cosine of 90.000000 is 0.000000 degrees

C Standard Library - <math.h>

❮ C Examples Quadratic Roots C Exercise Example75 ❯