该函数用于查找以弧度表示的角度的余弦。
考虑弧度“ x”。语法为:
float cos(float x); float cos(double x); float cos(long double x); double cos(integral x);
x :以弧度表示的值。
它返回[-1,1]范围内的角度的余弦值。
让我们看一个简单的例子,当x的值为正时。
#include#include 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()函数计算角度的余弦值。
让我们看一个简单的例子,当x的值为负数时。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-cos-function.html
来源:LearnFk无涯教程网
#include#include 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()函数将查找角度的余弦。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)