English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C library function cos() usage and example
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);
The parameters passed to the cos() function can be any value, including negative or positive numbers.
#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