Find power of a given number - C++ program

Implementation of power of given number is simple, Here is a short program that shows how to find power of a given number.For ex: 2 to the power 4 i.e. 2^4=16, and 4^2=8. Also 8 to the power 3 is 8^3=512. Logic of the program is given after the coding. Here is the output.

Implementation of power of given number is simple, Here is a short program that shows how to find power of a given number.For ex: 2 to the power 4 i.e. 2^4=16, and 4^2=8. Also 8 to the power 3 is 8^3=512. Logic of the program is given after the coding. Here is the output.

```//coding by himanshu singh
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int power,num,i=1;
cout<<"Enter a number: ";
cin>>num;
cout<<"nEnter power: ";
cin>>power;
while(i<=power){
i++;
}
cout<<num<< " to the power "<<power <<" is "<<answer;
return 0;
}```

(Note : I am using Dev C++ to implement this logic I also recommend you the same for you this is the best software for C++.)

## Find power of a given number: Logic

The logic is very simple, first we include header files iostream & stdio. Using namespace std is for standard use of standard input output stream like cout. We use three int number power, num and i. And we also use one long int 'answer'. Now we ask the user to enter the number and power when the user enter these terms a 'while' command is used which uses the logic (i<=power). Which means while the condition 'i' (i.e. 'i=1') is true, we will use logic (answer=answer*num;) which will multiply the number to the answer and will increment i by 1 (i++), till i <= power inserted. Now answer is given by answer term by cout.

You may also like:
Find max of n number by C++ coding

This is the simple logic for implementation of power of given number. Hope you like this tutorial. Please like and share it if you find it useful. Any suggestions, questions and request can be dropped into comment box below.

Name

ltr
item
MindxMaster: Find power of a given number - C++ program
Find power of a given number - C++ program
Implementation of power of given number is simple, Here is a short program that shows how to find power of a given number.For ex: 2 to the power 4 i.e. 2^4=16, and 4^2=8. Also 8 to the power 3 is 8^3=512. Logic of the program is given after the coding. Here is the output.
https://1.bp.blogspot.com/--xk86QRWRXs/VX1PuDxyZ7I/AAAAAAAAAJQ/PnmC-NlCX6c/s1600/power%2Bof%2Bnumber.png
https://1.bp.blogspot.com/--xk86QRWRXs/VX1PuDxyZ7I/AAAAAAAAAJQ/PnmC-NlCX6c/s72-c/power%2Bof%2Bnumber.png
MindxMaster
http://www.mindxmaster.com/2015/06/implement-power-of-given-number-in-c.html
http://www.mindxmaster.com/
http://www.mindxmaster.com/
http://www.mindxmaster.com/2015/06/implement-power-of-given-number-in-c.html
true
5332415103371288268
UTF-8