C program to find power of a number using pow function

Write a C program to input two numbers from user and find their power using pow() function. How to find power of a number in C programming. How to use pow() function in C programming.


Enter base: 5
Enter exponent: 2


5 ^ 2 = 25

Required knowledge

Arithmetic operators, Data types, Basic input/output

Program to find power of a number

 * C program to find power of any number

#include <stdio.h>
#include <math.h> // Used for pow() function

int main()
    double base, expo, power;

    /* Input two numbers from user */
    printf("Enter base: ");
    scanf("%lf", &base);
    printf("Enter exponent: ");
    scanf("%lf", &expo);

    /* Calculates base^expo */
    power = pow(base, expo);

    printf("%.2lf ^ %.2lf = %.2lf", base, expo, power);

    return 0;

%.2lf is used to print fractional value up to 2 decimal places.

Also check other approaches to find power of a number.

Read more -


Enter base: 5
Enter exponent: 3
5 ^ 3 = 125

Happy coding 😉

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He loves to learn new techs and write programming articles especially for beginners. He works at Vasudhaika Software Sols as a Software Design Engineer and manages Codeforwin. In short Pankaj is Web developer, Blogger, Learner, Tech and Music lover.

Follow on: Facebook | Twitter | Google | or

Comments and discussion
Have a doubt, write here. I will help my best.
Before commenting you must escape your source code before commenting. Paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>