#include <iostream.h>
#include <math.h>
#include <stdlib.h>
//f(x)=a0*x**n+a1*x**(n-1)+……+an
//该秦九韶算法运用了递归算法
double qin(int n,double*a,double x)
{
double result;
if(n==0) result=a[n];
else
{
result=qin(n-1,a,x)*x+a[n];
}
return result;
}
int main()
{
int n;
double *a,x;
cout<<"please input the length of array a[]:\n";
cin>>n;
cout<<"please input the value of x:\n";
cin>>x;
a=new double[n];
for(int j=0;j<n;j++)
{
cout<<"please input the value of a["<<j<<"]:\n";
cin>>a[j];
}
cout<<"The result of the function by qinjiushao algorimat is:\n";
cout<<qin(n-1,a,x)<<endl;
delete [n] a;
return 0;
}