#include <iostream>
using namespace std;
double P(int n, double x)
{
if(n==0)return 1.;
else if(n==1)return x;
double A = (2 * n - 1) * P(n-1,x);
double B = (n-1) * P(n-2, x);
return (A - B) / n;
}
int main()
{
int n;
double x;
cin >> n >> x;
cout << "P("<<n<<", "<<x<<")=" << P(n,x) << endl;
return 0;
}
【函数实训】第6关:递归求P函数
![](https://img-home.csdnimg.cn/images/20240711042549.png)