
编程计算X的N次方,要求用递归函数。别用太多的库函数,没学,急等,跪求,新人求助!!1
1个回答
展开全部
#include <iostream>
using namespace std;
int mul(int x, int N){
if (N == 0) return 1;
else if (N == 1) return x;
else{
int y = x * mul(x, N-1);
cout << "y = " << y << endl;
return y;
}
}
int main (){
cout << mul(3,4) << endl;
system("pause");
return 0;
}
using namespace std;
int mul(int x, int N){
if (N == 0) return 1;
else if (N == 1) return x;
else{
int y = x * mul(x, N-1);
cout << "y = " << y << endl;
return y;
}
}
int main (){
cout << mul(3,4) << endl;
system("pause");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询