代码:

#include <iostream>

using namespace std;

double f(double x,double *a,int n)
{
    double t=a[n];
    for(int i=n-1;i>=0;i--)
    {
        t=t*x+a[i];
    }
    return t;
}

int main()
{
    cout << "秦九韶算法" << endl;
    cout << "计算an*x^n +…+a2*x^2+a1*x+ a0" << endl;
    cout<<"输入x:";
    double x;
    cin>>x;
    cout<<endl;
    cout<<"输入n:";
    int n;
    cin>>n;

    double *a=new double[n+1];
    for(int i=0;i<=n;i++)
    {
        cout<<"输入a"<<i<<":";
        cin>>a[i];
    }
    double ans=f(x,a,n);
    cout<<endl<<"答案是:"<<ans<<endl;

    return 0;
}