You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
678 B
41 lines
678 B
3 years ago
|
#include <iostream>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int getPower(int x, int y) {
|
||
|
return (y == 0) ? 1 : x*getPower(x, y - 1);
|
||
|
}
|
||
|
|
||
|
double getPower(double x, int y) {
|
||
|
return (y == 0) ? 1 : x*getPower(x, y - 1);
|
||
|
}
|
||
|
|
||
|
// 不用三元运算符的写法
|
||
|
/*
|
||
|
int getPower(int x, int y) {
|
||
|
if (y == 0) {
|
||
|
return 1;
|
||
|
} else {
|
||
|
return x*getPower(x, y - 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
double getPower(double x, int y) {
|
||
|
if (y == 0) {
|
||
|
return 1;
|
||
|
} else {
|
||
|
return x*getPower(x, y - 1);
|
||
|
}
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
int main() {
|
||
|
// double x = 0;
|
||
|
// int y = 0;
|
||
|
|
||
|
int x = 0, y = 0;
|
||
|
cin >> x >> y;
|
||
|
|
||
|
cout << getPower(x, y);
|
||
|
}
|