📅  最后修改于: 2020-09-25 07:30:28             🧑  作者: Mango
此函数在
[Mathematics] cos x = cos(x) [In C++ Programming]
double cos(double x);
float cos(float x);
long double cos(long double x);
double cos(T x); // Here, T is an integral type.
cos() 函数采用一个以弧度为单位的强制性参数。
cos() 函数返回[-1,1]范围内的值。返回的值可以是double
, float
或long double
。
#include
#include
using namespace std;
int main()
{
double x = 0.5, result;
result = cos(x);
cout << "cos(x) = " << result << endl;
double xDegrees = 25;
// converting degrees to radians
x = xDegrees*3.14159/180;
result = cos(x);
cout << "cos(x) = " << result << endl;
return 0;
}
运行该程序时,输出为:
cos(x) = 0.877583
cos(x) = 0.906308
#include
#include
using namespace std;
int main()
{
int x = 1;
double result;
// result is in double
result = cos(x);
cout << "cos(x) = " << result << endl;
return 0;
}
运行该程序时,输出为:
cos(x) = 0.540302