C ++中的tan()函數(shù)返回以弧度為單位的角度(參數(shù))的正切值。
此函數(shù)在<cmath>頭文件中定義。
[數(shù)學] tan x = tan(x)
double tan(double x); float tan(float x); long double tan(long double x); double tan (T x); //為整型
tan()函數(shù)采用一個以弧度為單位的強制性參數(shù)(可以為正,負或0)。
tan()函數(shù)返回[-∞,∞]范圍內(nèi)的值。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long double x = 0.99999, result;
result = tan(x);
cout << "tan(x) = " << result << endl;
double xDegrees = 60.0;
//利用tan()函數(shù)將度數(shù)轉(zhuǎn)換為弧度
result = tan(xDegrees*3.14159/180);
cout << "tan(x) = " << result << endl;
return 0;
}運行該程序時,輸出為:
tan(x) = 1.55737 tan(x) = 1.73205
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long int x = 6;
double result;
result = tan(x);
cout << "tan(x) = " << result;
return 0;
}運行該程序時,輸出為:
tan(x) = -0.291006