#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;
}
原文地址:https://www.cnblogs.com/mathstudysharing/p/10500566.html
时间: 2024-11-02 18:52:14