A Little Fool

Fool For Free.

博客园 首页 新随笔 联系 订阅 管理
#include <iostream>
using namespace std;

double hornerExp(double a[], int n, double x);

int main()
{
    
int n;
    
double *a;
    
double x;

    cout
<<"Input the n (a0, a1, , an):\n";
    cin
>>n;

    a 
= new double[n+1];
    cout
<<"Input a0, a1, , an\n";
    
for (int i = 0; i <= n; i++) {
        cin
>>a[i];
    }

    cout
<<"Input the x"<<endl;
    cin
>>x;

    cout
<<"y = "<<hornerExp(a, n, x)<<endl;

    delete []a;

    
return 0;
}


double hornerExp(double a[], int n, double x)
{
    
double y = 0.0;

    
for (int i = n; i >= 1--i) {
        y 
+= a[i];
        y 
*= x;
    }
    y 
+= a[0];

    
return y;
}
posted on 2009-04-06 22:53  HenryRead  阅读(1223)  评论(0编辑  收藏  举报