C ++中的tan()函数返回以弧度为单位的角度(参数)的正切值。
此函数在<cmath>头文件中定义。
[数学] tan x = tan(x)
double tan(double x); float tan(float x); long double tan(long double x); double tan (T x); //为整型
tan()函数采用一个以弧度为单位的强制性参数(可以为正,负或0)。
tan()函数返回[-∞,∞]范围内的值。
#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()函数将度数转换为弧度
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