
C 速查手冊
11.1.11 sin()
math.h 的函數 (function) sin() 回傳參數 (parameter) 的正弦值,單位為弧度。預設回傳值 (return value) 及參數的資料型態 (data type) 為 double ,另有 float 型態的 sinf() , long double 型態的 sinl() 。
sin() 的函數原型 (prototype) 如下
| double sin(double); |
| float sinf(float); |
| long double sinl(long double); |
以下程式示範函數 sin() 的使用
#include <stdio.h>
#include <math.h>
int main(void)
{
double i = -1.0;
while (i <= 1.0) {
printf("%f\n", sin(i));
i += 0.1;
}
return 0;
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:csin.c
功能:示範 math.h 中函數 sin() 的使用
作者:張凱慶 */
編譯後執行,結果如下
| $ gcc csin.c |
| $ a.out |
| -0.841471 |
| -0.783327 |
| -0.717356 |
| -0.644218 |
| -0.564642 |
| -0.479426 |
| -0.389418 |
| -0.295520 |
| -0.198669 |
| -0.099833 |
| -0.000000 |
| 0.099833 |
| 0.198669 |
| 0.295520 |
| 0.389418 |
| 0.479426 |
| 0.564642 |
| 0.644218 |
| 0.717356 |
| 0.783327 |
| 0.841471 |
| $ |
