C++ tan() 函数使用方法及示例
C ++中的tan()函数返回以弧度为单位的角度(参数)的正切值。
此函数在<cmath>头文件中定义。
[数学] tan x = tan(x)
tan()原型(从C ++ 11标准开始)
double tan(double x); float tan(float x); long double tan(long double x); double tan (T x); //为整型
tan()参数
tan()函数采用一个以弧度为单位的强制性参数(可以为正,负或0)。
tan()返回值
tan()函数返回[-∞,∞]范围内的值。
示例1:tan()如何在C ++中工作?
#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
示例2:具有整数类型的tan()函数
#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