N阶拉格朗日插值C语言
main()
{int i,n;
int k;
int x[5]={0,1,2,3,4};
float y[5]={1,0.95,0.82,0.71,0.43};
float p,s;
float b;
s=0.0;
printf("input b,n:");
scanf("%f,%d",&b,&n);
for(k=0;k<n;k++)
{p=1.0;
for(i=0;i<n;i++)
if(k!=i)
p*=(b-x[i])/(x[k]-x[i]);
s+=p*y[k];
}
printf("%5.4f",s);
}
看下有错么
运行精确不够