- In this program, we declare three double variables
base,exponent, andresult. We useprintf()andscanf()to get the values of the base and exponent from the user. - We then use the
pow()function to calculate the power of the number. Thepow()function takes two arguments: the base and the exponent, and returns the result of raising the base to the exponent power. - Finally, we print out the result using
printf(). Note that we use the%lfformat specifier to print out the double precision floating point value of the result.
#include <stdio.h>
#include <math.h>
int main() {
double base, exponent, result;
// Get the base and exponent from the user
printf("Enter the base: ");
scanf("%lf", &base);
printf("Enter the exponent: ");
scanf("%lf", &exponent);
// Calculate the power using the pow() function
result = pow(base, exponent);
// Print the result
printf("%lf raised to the power of %lf is %lf\n", base, exponent, result);
return 0;
}
OUTPUT
Enter the base: 2
Enter the exponent: 3
2.000000 raised to the power of 3.000000 is 8.000000