C cos()

C cos() Prototype

double cos(double x);

Function cos() takes a single argument in radians and returns a value in type double.

The value returned by cos() is always in the range: -1 to 1.

It is defined in <math.h> header file.


[Mathematics] cosx = cos(x) [In C Programming]

In order to use cos() for floats or long double, you can use the following prototype:

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

C cos() range

The arguments passed to cos() function can be any value, either negative or positive.

Example: C cos() function

#include <stdio.h>
#include <math.h>
#define PI 3.141592654

int main()
{
   double arg = 30, result;

   // Converting to radian
   arg = (arg * PI) / 180;
   result = cos(arg);

   printf("cos of %.2lf radian = %.2lf", arg, result);

   return 0;
}

Output

cos of 0.52 radian = 0.87
Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community