用递归的方法编写函数计算X的Y次幂,在主程序中实现输入输出

C++编写
2025-03-10 22:53:06
推荐回答(2个)
回答1:

#include
using namespace std;
double cal(int x ,int y) {
if(y == 1) {
return x;
}
return cal(x, y - 1) * x;
}

void main()
{
int x, y;
cout<<"enter x : " < cin >> x;
cout<<"enter y : " << endl;
cin >> y;
cout <<"result is :"<}

回答2:

#include
using
namespace
std;
double
cal(int
x
,int
y)
{
if(y
==
1)
{
return
x;
}
return
cal(x,
y
-
1)
*
x;
}
void
main()
{
int
x,
y;
cout<<"enter
x
:
"
<cin
>>
x;
cout<<"enter
y
:
"
<<
endl;
cin
>>
y;
cout
<<"result
is
:"<}