C++ <cmath> - cos() Function
The C++ <cmath> cos() function returns trigonometric cosine of an angle (angle should be in radians). In the graph below, cos(x) vs x is plotted.
Syntax
double cos (double x); float cos (float x); long double cos (long double x);
double cos (double x); float cos (float x); long double cos (long double x); //additional overloads for integral types double cos (T x);
Parameters
x |
Specify the angle in radian. |
Return Value
Returns the trigonometric cosine of an angle.
Example:
In the example below, cos() function is used to find out the trigonometric cosine of an angle.
#include <iostream> #include <cmath> using namespace std; int main (){ //M_PI - value of PI from math.h cout<<cos(M_PI/6)<<"\n"; cout<<cos(M_PI/4)<<"\n"; cout<<cos(M_PI/3)<<"\n"; return 0; }
The output of the above code will be:
0.866025 0.707107 0.5
❮ C++ <cmath> Library