C ++中的sin()函數(shù)返回以弧度表示的角度(參數(shù))的正弦值。
此函數(shù)在<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()函數(shù)采用一個(gè)以弧度為單位的強(qiáng)制性參數(shù)。
sin()函數(shù)返回[-1,1]范圍內(nèi)的值。返回的值是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; //將角度轉(zhuǎn)換為弧度 x = xDegrees*3.14159/180; result = sin(x); cout << "sin(x) = " << result << endl; return 0; }
運(yùn)行該程序時(shí),輸出為:
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; }
運(yùn)行該程序時(shí),輸出為:
sin(x) = -0.841471