无涯教程-cos(x)函数

136 阅读1分钟

该函数用于查找以弧度表示的角度的余弦。

cos - 语法

考虑弧度“ x”。语法为:

float cos(float x);
float cos(double x);
float cos(long double x);
double cos(integral x);

Note: 如果传递的值是整数类型,则将其强制转换为double。

cos - 参数

x :以弧度表示的值。

cos - 返回值

它返回[-1,1]范围内的角度的余弦值。

cos - 例子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()函数计算角度的余弦值。

cos - 例子2

让我们看一个简单的例子,当x的值为负数时。

#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()函数将查找角度的余弦。

参考链接

www.learnfk.com/c++/cpp-mat…