需要一个验证n次拉格朗日插值定理的源代码,最好是C语言做的,C++的也可以,谢谢

热心网友

抄一个给你,自己打不够麻烦的#include#include#includetypedef struct data{ float x; float y;}Data;//变量x和函数值y的结构Data d[20];//最多二十组数据float f(int s,int t)//牛顿插值法,用以返回插商{ if(t==s+1) return (d[t]。y-d[s]。y)/(d[t]。x-d[s]。x); else return (f(s+1,t)-f(s,t-1))/(d[t]。x-d[s]。x); }float Newton(float x,int count){ int n; while(1) { coutn; if(ncount; if(countd[i]。x; coutd[i]。y; system("cls"); } coutx; while(1) { int choice=3; coutchoice;//取得用户的选择项 if(choice==2) { cout<<"你选择了牛顿插值计算方法,其结果为:"; y=Newton(x,count);break;//调用相应的处理函数 } if(choice==1) { cout<<"你选择了拉格朗日插值计算方法,其结果为:"; y=lagrange(x,count);break;//调用相应的处理函数 } if(choice==0) break; system("cls"); cout<<"输入错误!!!!"<