Compute Power of a Number

Compute Power of a Number” is again basic problem of programming for beginners. Here, we are given a base and exponent number, entered by users and our task is to write a program to compute the power of a number, baseexponent.

23 = 2 * 2 * 2 = 8

Example

INPUT:
Base = 2, Exponent = 3
OUTPUT:
8

To compute the power of a number, simply loop can be used.

C++ Program to compute Power of a Number is as follows:

#include<bits/stdc++.h>  
using namespace std;  
int main()  
{  
    //Scan the base and exponent  
    int base,exponent;  
    cout<<"Enter the base and exponent:";  
    cin>>base>>exponent;  
      
    // Compute the Power  
    int Power = 1;  
    for(int i = 1 ; i <= exponent ; i++)  
    {  
        Power = Power * base;  
    }  
      
    // Printing the result  
    cout<<Power;  
}  
OUTPUT:
Enter the base and exponent: 2 3
8

Related Posts:

  1. Program to find Quotient and Remainder.
  2. Program to find largest amongst three numbers.
  3. Program to find factorial of a number.
  4. Program to find GCD of two numbers.
  5. Program to find LCM of two numbers.
  6. Program to check whether entered number is odd or even.
  7. Program to check whether entered number is prime number or not.
  8. Program to check whether entered number is palindrome or not.
  9. Program to check whether entered number is Armstrong Number or Not.
  10. Program to convert binary number to octal number.
  11. Program to convert binary number to decimal number.
  12. Program to convert binary number to hexadecimal number.
  13. Program to convert octal number to binary number.
  14. Program to convert octal number to decimal number.
  15. Program to convert octal number to hexadecimal number.
  16. Program to convert decimal number to binary number.
  17. Program to convert decimal number to octal number.
  18. Program to convert decimal number to hexadecimal number.
  19. Program to convert hexadecimal number to binary number.
  20. Program to convert hexadecimal number to octal number.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *