c/c++课的作业合集,都是很简单的文件。
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.
 
 
 
cpp-work/archive/p97_3-15.cpp

40 lines
678 B

#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);
}