#define N 100
#include"iostream.h"
float Y[N],X[N];
int n,k=1;
float x;
float sum,s;
float f(int i,int j)
{
float sum1=0;
if(j-i==1) sum1=(Y[j]-Y[i])/(X[j]-X[i]);
else sum1=(f(i+1,j)-f(i,j-1))/(X[j]-X[i]);
if(i==0&&j==k)
{
sum+=sum1*s;
s*=(x-X[k]);
k++;
}
return sum1;
}
void main()
{
cout<<"输入你想进行的X次多项试计算:";
cin>>n;
for(int i=0;i<=n;i++)
{
cout<<"输入第"<<i+1<<"个点的坐标:";
cin>>X[i]>>Y[i];
}
sum=Y[0];
cout<<"输入你想进行计算的x值:";
cin>>x;
s=(x-X[0]);
f(0,n);
cout<<sum;
}
posted on 2007-06-09 12:15
星梦情缘 阅读(1505)
评论(5) 编辑 收藏 引用 所属分类:
数据结构的所有实现程序