在C語言中,可以使用pow()函數(shù)來計(jì)算次冪。該函數(shù)需要包含<math.h>頭文件。
例如,要計(jì)算2的3次冪,可以使用以下代碼:
#include <stdio.h>
#include <math.h>
int main() {
double base = 2.0;
double exponent = 3.0;
double result = pow(base, exponent);
printf("%f raised to the power of %f is %f\n", base, exponent, result);
return 0;
}
運(yùn)行以上代碼,將輸出:
2.000000 raised to the power of 3.000000 is 8.000000
這樣就可以使用pow()函數(shù)計(jì)算次冪了。