
C 速查手冊
11.1.8 pow()
math.h 的函數 (function) pow() 需要兩個參數 (parameter) ,第二個參數作為第一個參數的指數,回傳指數運算結果。預設回傳值 (return value) 及參數的資料型態 (data type) 為 double ,另有 float 型態的 powf() , long double 型態的 powl() 。
pow() 的函數原型 (prototype) 如下
| double pow(double, double); |
| float powf(float, float); |
| long double powl(long double, long double); |
以下程式示範函數 pow() 的使用
#include <stdio.h>
#include <math.h>
int main(void)
{
printf("%f\n", pow(2, 3));
printf("%f\n", pow(2, 3.2));
printf("%f\n", pow(6, 8));
printf("%f\n", pow(10, 6));
printf("%f\n", pow(7.3, 5));
printf("%f\n", pow(6.9, 9.3));
return 0;
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:cpow.c
功能:示範 math.h 中函數 pow() 的使用
作者:張凱慶 */
編譯後執行,結果如下
| $ gcc cpow.c |
| $ a.out |
| 8.000000 |
| 9.189587 |
| 1679616.000000 |
| 1000000.000000 |
| 20730.715930 |
| 63284382.069367 |
| $ |
