Banner Header

Thursday, 12 July 2018

C Program to Calculate the Power of a Number

C Program to Calculate the Power of a Number

Example on how to calculate the power of a number if the exponent is an integer. Also, you will learn to compute the power using pow() function.



The program below takes two integers from the user (a base number and an exponent) and calculates the power.
For example: In case of 23
  • 2 is the base number
  • 3 is the exponent
  • And, the power is equal to 2*2*2

Example #2: Power Using pow() Function

#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
    int base, exponent, result;
    printf("Enter a base number: ");
    scanf("%d", &base);
    printf("Enter an exponent: ");
    scanf("%d", &exponent);
    // calculates the power
    result = pow(base, exponent);
    printf("%d^%d = %d", base, exponent, result);
printf("\nSubscribe My Channel");
    return 0;
getch();
}

Output

Enter the value of base = 2
Enter the value of Exponent= 2
2^2 = 4

Click on the download button to download file


download button
C Program to Calculate the Power of a Number Reviewed by Waqas Ahmed Mir PC on July 12, 2018 Rating: 5 C Program to Calculate the Power of a Number Example on how to calculate the power of a number if the exponent is an integer. Also, you w...
Next
This is the most recent post
Older Post

No comments: