#include <iostream> using namespace std; int Polynomial(double x,int n); int main () { int n; double x; //输入 cout<<"请输入一个实数:"; cin>>x; cout<<"请输入求n阶勒让德多项式的n值:"; cin>>n; cout<<"该n阶勒让德多项式的值为:"<<Polynomial(x,n)<<endl; return 0; } int Polynomial(double x,int n)//求n阶勒让德多项式的值的函数 { double p; if(n==0) { p=1; } else if(n==1) { p=x; } else { p=((2*n-1)*x*Polynomial(x,n-1)-(n-1)*Polynomial(x,n-2))/n; } return p; }