#include <iostream>
using namespace std;
/*
*计算格式:Z[k]=x*Z[k-1]+a[n-k-1];
*/
template <class T,class X,class Z>
//a:数组 size:数组中最后一个元素 x:系数x z:存放乘积 k:乘积数组中索引
Z Ploy_number(const T *a,int size,const X x,Z *z,int k){
if(k==0)
{
z[k]=a[size];
cout<<"k:"<<k<<" z["<<k<<"]:"<<z[k]<<endl;
return z[k];
}
z[k]=Ploy_number(a,size,x,&z[k-1],k-1)*x+*(a+size-k);
cout<<"k:"<<k<<" z["<<k<<"]:"<<z[k]<<" x:"<<x<<endl;
return z[k];
}
int main(){
int a[]={1,2,3,4,5};
int z[5];
int num;
int x=1;
num=Ploy_number(a,4,x,z,4);
cout<<"x:"<<num<<endl;
}
|