1 回答
已采纳
天将明96
TA贡献15条经验 获得超13个赞
#include <stdio.h>
//循环版
int myPow1(int x, int n) {
int result = 1;
if (n == 0) {
return result;
}
for (int i = 0; i < n; i++) {
result *= x;
}
return result;
}
//递归版
int myPow2(int x, int n) {
if (n == 0)
return 1;
if (n == 1)
return x;
if (n > 1)
return myPow2(x, n - 1) * x;
}
int main() {
printf("%d\n", myPow1(5, 4));
printf("%d\n", myPow2(5, 4));
}
如果满足要求,望采纳!<(▰˘◡˘▰)>
- 1 回答
- 0 关注
- 3271 浏览
添加回答
举报
0/150
提交
取消
