Programming Example
C program to find power of a number using pow function
Study this program carefully to understand the logic, output, and explanation in a structured way.
/**
* C program to find power of any number
*/
#include"stdio.h"
#include "math.h" //Used for pow() function
int main()
{
double x, y, power;
// Reads two numbers from user to calculate power
printf("Enter base: ");
scanf("%lf", &x);
printf("Enter exponent: ");
scanf("%lf", &y);
// Calculates x^y
power = pow(x, y);
printf("x ^ y = %.2lf \n", power);
return 0;
}
Enter base: 3
Enter exponent: 2
x ^ y = 9.00
Press any key to continue . . .
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.