How is the pow function used in the C language?
In C language, the pow function in the math.h header file can be used to perform power operations.
#include <stdio.h>
#include <math.h>
int main() {
double base, exponent, result;
printf("Enter base number: ");
scanf("%lf", &base);
printf("Enter exponent: ");
scanf("%lf", &exponent);
result = pow(base, exponent);
printf("%.2lf^%.2lf = %.2lf", base, exponent, result);
return 0;
}
The above code prompts the user to enter a base and an exponent, calculates the result using the pow function, and then outputs the result to the screen. It should be noted that the parameters and return value of the pow function are both of type double.