C Program To Find Power Of A Number Using pow Function

Share Your Love

In this post I am going to solve one problem power of a number using pow function.


How to solve this problem?

Here user first input two numbers and find there power using pow() function. So, here how to find power of two number in C Programming. How to use pow() function in C Programming.


Enter base: 5
Enter exponent: 2

5 ^ 2 = 25

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;


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

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


line no. -1 to 3 is a comment to "find power of any number"


line no. 5 and 6 used header files "<stdio.h> <math.h>" line no. 5 for scanf() and printf() and line no. 6 used for pow() "<math.h>"


line no. 8 "int main()" execution begins here.


line no. 13 and 14 used for print on console (printf("Enter base: ");) and take input from user(scanf("%lf", &base);)


line no. 15 and 16 used for input expo by help of [
printf("Enter exponent: "); => used for console before take input
    scanf("%lf", &expo); ]


line no 18 used for comment and 19 used for solving the problem by expression [/* Calculates base^expo */
    power = pow(base, expo);


line no 21 print by help of printf() 
[printf("%.2lf ^ %.2lf = %.2lf", base, expo, power);] here we used %.2lf for fractional value up to 2 decimal places.


return 0; //successful execution by return to main()

Please comment and share this post if you find valuable information and wants to contribute please WhatsApp us.

Share Your Love
Avatar photo
Lingaraj Senapati

Hey There! I am Lingaraj Senapati, the Founder of lingarajtechhub.com My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.

Articles: 429

Newsletter Updates

Enter your email address below to subscribe to our newsletter