quantum

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include<iostream>
const int coef_num=5;
using namespace std;
template<typename T> inline T horner(T x,T n,T list[]);
int main()
{
int list[coef_num]={1,2,1,3,6};
cout<<"输入未知数 x= ";
int x;
cin>>x;
int sum=horner(x,coef_num,list);
cout<<"Horner函数值: "<<sum<<endl;
return 0;
}
template<typename T> inline T horner(T x,T index,T list[])
{
int sum=list[--index];
--index;
while(index>=0)
sum=sum*x+list[index--];
return sum;
}


 

posted on 2012-02-28 16:49  quantum  阅读(204)  评论(0)    收藏  举报