方法一:直接法
计算多项式的值最容易想到的方法就是直接法,直接把多项式的每一项相加起来。
double f2(int n , double a[] , double x)
{
int i;
double p = a[0];
for(i = 1;i < n ;i++){
p += (a[i] * pow(x,i));
}
return p;
}
该方法中,pow函数在#include<math.h>中
方法二:秦九韶算法
double f1(int n , double a[] , double x)
{
int i;
double p = a[n