-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerofaNum.cpp
More file actions
46 lines (41 loc) · 799 Bytes
/
PowerofaNum.cpp
File metadata and controls
46 lines (41 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*Find power of a number
Send Feedback
Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to print the answer.
Note : For this question, you can assume that 0 raised to the power of 0 is 1
Input format :
Two integers x and n (separated by space)
Output Format :
x^n (i.e. x raise to the power n)
Constraints:
0 <= x <= 8
0 <= n <= 9
Sample Input 1 :
3 4
Sample Output 1 :
81
Sample Input 2 :
2 5
Sample Output 2 :
32
*/
program:-
#include<iostream>
using namespace std;
int main() {
int x,n;
cout<<"Enter the value of x and n";
cin>>x>>n;
int i=1;
int sol=x;
if(n==0){
sol=1;
cout<<sol;
}
else{
while(i<n){
sol=sol*x;
i=i+1;
}
cout<<sol<<endl;
}
}