
C 速查手冊
11.1.13 tan()
math.h 的函數 (function) tan() 回傳參數 (parameter) 的正切值,單位為弧度。預設回傳值 (return value) 及參數的資料型態 (data type) 為 double ,另有 float 型態的 tanf() , long double 型態的 tanl() 。
tan() 的函數原型 (prototype) 如下
| double tan(double); |
| float tanf(float); |
| long double tanl(long double); |
以下程式示範函數 tan() 的使用
#include <stdio.h>
#include <math.h>
int main(void)
{
double i = -1.0;
while (i <= 1.0) {
printf("%f\n", tan(i));
i += 0.1;
}
return 0;
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:ctan.c
功能:示範 math.h 中函數 tan() 的使用
作者:張凱慶 */
編譯後執行,結果如下
| $ gcc ctan.c |
| $ a.out |
| -1.557408 |
| -1.260158 |
| -1.029639 |
| -0.842288 |
| -0.684137 |
| -0.546302 |
| -0.422793 |
| -0.309336 |
| -0.202710 |
| -0.100335 |
| -0.000000 |
| 0.100335 |
| 0.202710 |
| 0.309336 |
| 0.422793 |
| 0.546302 |
| 0.684137 |
| 0.842288 |
| 1.029639 |
| 1.260158 |
| 1.557408 |
| $ |
