C++ Math cos()
C++ Math cos()
该函数用于查找以弧度表示的角度的余弦。
语法
考虑弧度" x"。语法为:
float cos(float x);
float cos(double x);
float cos(long double x);
double cos(integral x);
注意: 如果传递的值是整数类型,则将其强制转换为double。
参数
x : 以弧度表示的值。
返回值
它返回在[-1,1]范围内的角度的余弦值。
示例1
让我们看一个简单的示例,当x的值为正时。
#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;
}
输出:
Cosine of an angle is : 0.50046
在此示例中,当度数等于60时,cos()函数将计算角度的余弦值。
示例2
x的值为负时的简单示例。
#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;
}
输出:
Cosine of an angle is :0.000796327
在此示例中,当值为负但与cos(-x)= cos(x)相同时,cos()函数将查找角度的余弦。