Popular Tutorials
Start Learning CCertification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
C cos()
The cos() function computes the cosine of an argument.
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?