tan() 函数定义在 math.h 头文件中。它有助于返回给定弧度值的正切值。
double tan(double x) #where x can be in int, float or long double
tan() 函数接受一个参数,该参数是一个表示以弧度表示的角度的值。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 双精度浮点数值 | 一个 double 类型的值,表示以弧度表示的角度 | 必需 |
tan() 函数的返回值是介于 1 和 -1 之间的数字。
| 输入 | 返回值 |
|---|---|
| -1 < x ≥ 1 | 一个大于或等于 0 的数字 |
| x < -1 | NaN (非数字) |
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main () {
double v;
double output;
v = 2.3;
output = tan(v);
printf("The value of tan(%.2lf) = %.2lf\n", v, output);
v = -2.3;
output = tan(v);
printf("The value of tan(%.2lf) = %.2lf\n", v, output);
v = 0;
output = tan(v);
printf("The value of tan(%.2lf) = %.2lf\n", v, output);
return 0;
}
输出
The value of tan(2.30) = -1.12 The value of tan(-2.30) = 1.12 The value of tan(0.00) = 0.00
#include <stdio.h>
#include <math.h>
int main () {
double A=0.5,B=1;
printf("The tangent value of %f is:%f\n",A,tan(A));
printf("The tangent value of %f is:%f\n",B,tan(B));
return 0;
}
输出
The tangent value of 0.500000 is: 0.546302 The tangent value of 1.000000 is: 1.557408