cos()函数以及C ++中的示例
C++cos()函数
cos()函数是cmath标头的库函数,用于查找给定数字(角度)的余弦值,接受数字(x)并返回角度x弧度的余弦值。
cos()函数语法:
cos(x);
参数:x–是要计算余弦值的弧度角值。
返回值:double-返回double类型值,该值是给定角度x弧度的余弦值。
示例
Input:
float x = 2.45;
Function call:
cos(x);
Output:
-0.770231C++代码演示cos()函数示例
//示例
//cos()功能
#include <iostream>
#include <cmath>
using namespace std;
//main()部分
int main(){
float x;
x = -10.23;
cout<<"cos("<<x<<"): "<<cos(x)<<endl;
x = 0;
cout<<"cos("<<x<<"): "<<cos(x)<<endl;
x = 2.45;
cout<<"cos("<<x<<"): "<<cos(x)<<endl;
return 0;
}输出结果
cos(-10.23): -0.692952 cos(0): 1 cos(2.45): -0.770231
参考:C++cos()函数