#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;
}

浙公网安备 33010602011771号