C++ Math cos
The function is utilized to determine the cosine value of an angle specified in radians.
Syntax
Consider a radian 'x'. Syntax would be:
float cos(float x);
float cos(double x);
float cos(long double x);
double cos(integral x);
Note: If the value passed is an integer type, then it is cast to double.
Parameter
x : Value specified in terms of radian.
Return value
It provides the cosine value of an angle within the interval of [-1, 1].
Example 1
Let's examine a basic scenario where the value of x is greater than zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double degree=60;
double d=60*3.14/180;
cout<<"Cosine of an angle is : "<<cos(d);
return 0;
}
Output:
Cosine of an angle is : 0.50046
In this instance, the cos function computes the cosine value of an angle with a measurement of 60 degrees.
Example 2
Let's explore a basic scenario where the value of x is less than zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double degree= -90;
double radian=degree*3.14/180;
cout<<"Cosine of an angle is :"<<cos(radian);
return 0;
}
Output:
Cosine of an angle is :0.000796327
In this instance, the cos function calculates the cosine of an angle even if the angle is negative, with the property that cos(-x) remains equivalent to cos(x).