C 语言 tan() 函数用于计算角度的正切值(角度以弧度为单位),返回 double。
原型
double tan(double x);参数
x- 角度(弧度,double)。
示例
#include <stdio.h>
#include <math.h>
int main() {
printf("tan(0) = %.1f\n", tan(0));
printf("tan(pi/4) = %.4f\n", tan(M_PI / 4));
return 0;
}输出:
tan(0) = 0.0
tan(pi/4) = 1.0000注意事项
使用 math.h 的函数时,多数编译器需要链接数学库(编译选项 -lm)。三角函数使用弧度制,不是角度;想用角度先乘以 pi/180 转换。