Home / Programs / C program to find power of a number using pow function
Programming Example

C program to find power of a number using pow function

👁 3,407 Views
💻 Practical Program
📘 Step by Step Learning
Study this program carefully to understand the logic, output, and explanation in a structured way.

Program Code

/**
 * 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;
} 

Output

Enter base: 3
Enter exponent: 2
x ^ y = 9.00
Press any key to continue . . .

How to learn from this program

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.