Power
Power
Send Feedback
Power
Two integers x and n (separated by space)
x^n (i.e. x raise to the power n)
0 <= x <= 30
0 <= n <= 30
3 4
81
2 5
32
int power(int x, int n) { /* Don't write main(). Don't read input, it is passed as function argument. Return output and don't print it. Taking input and printing output is handled automatically. */ if(n==0) return 1;
return x*power(x,n-1);
}
#include<iostream>using namespace std;
int power(int x, int n) { /* Don't write main(). Don't read input, it is passed as function argument. Return output and don't print it. Taking input and printing output is handled automatically. */ if(n==0) return 1;
return x*power(x,n-1);
}
int main(){ int x, n; cin >> x >> n; cout << power(x, n) << endl;}
Comments
Post a Comment