English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Online tools

O)

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C language flow control

C language structure

C language file

C language other

C language reference manual

C Standard Library <math.h>

C library function cos() usage and example

The cos(x) function returns the cosine value of the parameter x.

C cos() function prototype

double cos(double x);

The cos() function accepts a parameter in radians and returns a double type value.-1The value returned by cos() is always between1and

It is between<math.h>Defined in the header file.

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

To use cos() with long double or float, you can use the following prototype:

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

C cos() function range

The parameters passed to the cos() function can be any value, including negative or positive numbers.

Example: C cos() function

#include <stdio.h>
#include <math.h>
#define PI 3.141592654
int main()
{
   double arg = 30, result;
   // converted to radians
   arg = (arg * PI) / 180;
   result = cos(arg);
   printf("cos %.0f2lf Cosine value = %.0f2lf", arg, result);
   return 0;
}

Output Result

cos 0.52 Cosine value = 0.87

C Standard Library <math.h>