我在弄清楚这个特定程序的递归时遇到了一些麻烦。我尝试了一些不同的选项,但我对递归函数是全新的。程序中唯一允许我修改的部分是函数 B 内部。该函数计算:Bn(a) = Bn−1(a) × Bn−2(a),其中 B1(a) = B2(a ) = 一个。所以 B1(a) = a | B2(a) = 一个 | B3(a) = a^2 | B4(a) = a^3 | B5(a) = a^5 | ETC...
#include <iostream>
using namespace std;
float B(float a, int n)
{
//Here is where I'm having an issue...
}
int main(void)
{ cout << "Input a float a, and an int n > 0: ";
float a; int n;
cin >> a >> n;
cout << "B(" << a << ")_" << n << " = " << B(a,n) << endl;
return 0;
}