/**
* 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 understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.