How do you calculate a power in the C language?
In C language, you can use the pow function to calculate the power of a number.
The prototype of the function is:
double pow(double x, double y);
x represents the base, y represents the exponent.
The sample code is shown below:
#include <stdio.h>
#include <math.h>
int main() {
double base, exponent, result;
printf("请输入底数:");
scanf("%lf", &base);
printf("请输入指数:");
scanf("%lf", &exponent);
result = pow(base, exponent);
printf("%.2lf的%.2lf次方为%.2lf\n", base, exponent, result);
return 0;
}
After running the program, input the base and exponent, the program will calculate and display the result.