在C語言中,可以使用pow函數(shù)來求一個數(shù)的次方。
函數(shù)原型為:
double pow(double x, double y);
其中,x表示底數(shù),y表示指數(shù)。
示例代碼如下:
#include <stdio.h>
#include <math.h>
int main() {
double base, exponent, result;
printf("請輸入底數(shù):");
scanf("%lf", &base);
printf("請輸入指數(shù):");
scanf("%lf", &exponent);
result = pow(base, exponent);
printf("%.2lf的%.2lf次方為%.2lf\n", base, exponent, result);
return 0;
}
運行程序后,輸入底數(shù)和指數(shù),程序會計算并輸出結果。