c语言-勒让德多项式求解+时间测定

#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;

float LRD(int n,double x){
  double s;
  if(n==0) s=1.0;
  else if(n==1) s=x;
  else s=((2*n-1)*x*LRD(n-1,x)-(n-1)*LRD(n-2,x))/n;
  return s;
}


int main(){
  int n;
  double sum,x;
  clock_t start,finish;
  double total;
  cout<<"Please enter an natural number and a real number:"<<endl;
  cin>>n>>x;
  start=clock();
  sum=LRD(n,x);
  finish=clock();
  total=(double)(finish-start);
  cout<<"The value is:"<<sum<<endl;
  cout<<"The time of this running is "<<total<<endl;
  return 0;
}

猜你喜欢

转载自www.cnblogs.com/mathstudysharing/p/10500566.html