quantum

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include<iostream>
const int coef_num=5;
using namespace std;
template<typename T> inline T horner(T x,T index,T coef,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-1,list[4],list);
cout<<"Horner函数值: "<<sum<<endl;
return 0;
}
template<typename T> inline T horner(T x,T index,T coef,T list[])
{
if(index){
coef=coef*x+list[--index];
return horner(x,index,coef,list);
}
return coef;
}


 

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