C 语言 pow() 函数用于计算 x 的 y 次方(x^y),返回 double 结果。
原型
double pow(double x, double y);第一个参数是底数,第二个参数是指数。int/float 变量需用类型转换,如 pow((double)base, (double)power)。
示例
#include <stdio.h>
#include <math.h>
int main() {
double base, power, result;
printf("输入底数: ");
scanf("%lf", &base);
printf("输入指数: ");
scanf("%lf", &power);
result = pow(base, power);
printf("%.1lf^%.1lf = %.2lf\n", base, power, result);
return 0;
}输出:
输入底数: 2.5
输入指数: 3.4
2.5^3.4 = 22.54注意事项
使用 math.h 的函数时,多数编译器需要链接数学库(编译选项 -lm,如 gcc test.c -lm -o test)。所有三角函数使用弧度制。