Thursday, April 2, 2020

c program to calculate power of a number

C program to calculate power of a number

  • The program takes two integer from user and then calculate power.
          For example : 2 pow 3 .
  • In case 2 is base number and 3 is exponent number.  (2*2*2)
#include 
int main() 
{
    int base, exp; // integer values 
    long long result = 1; // constant values
    printf("Enter a base number: "); // User enter 
    scanf("%d", &base); //storing values
    printf("Enter an exponent: "); // User enter 
    scanf("%d", &exp); // storing values

    while (exp != 0) // while loop
    {
        result = result * base;
        --exp;
    }
    printf("Answer = %lld", result); // finalize result
    return 0;
}
Output


Ente a base number 3
Enter exponent number 4
Answer = 81
Happy Coding

Thanks for visiting my Blog.

Have any problem, feel free to contact us via Email : uoslondy@gmail.com

Have a good day!
Location: Pakistan

0 comments:

Post a Comment

Recent Posts