C ++中的sin()函数返回以弧度表示的角度(参数)的正弦值。
此函数在<cmath>头文件中定义。
[Mathematics] sin x = sin(x) [C++]
double sin(double x); float sin(float x); long double sin(long double x); double sin (T x); //为整型
sin()函数采用一个以弧度为单位的强制性参数。
sin()函数返回[-1,1]范围内的值。返回的值是double,float或long double。
#include <iostream> #include <cmath> using namespace std; int main() { double x = 0.439203, result; result = sin(x); cout << "sin(x) = " << result << endl; double xDegrees = 90.0; //将角度转换为弧度 x = xDegrees*3.14159/180; result = sin(x); cout << "sin(x) = " << result << endl; return 0; }
运行该程序时,输出为:
sin(x) = 0.425218 sin(x) = 1
#include <iostream> #include <cmath> using namespace std; int main() { int x = -1; double result; result = sin(x); cout << "sin(x) = " << result << endl; return 0; }
运行该程序时,输出为:
sin(x) = -0.841471