?? lagrange.cpp
字號:
//Lagrange's interpolation formula
#include<stdio.h>
#include<conio.h>
main()
{
float x[20],y[20],p1,p2,s,xv;
int n,i,j;
printf("How many sets of values do you want to give:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter x%d,y%d:",i+1,i+1);
scanf("%f%f",&x[i],&y[i]);
}
label:
printf("\nEnter the value of x:");
scanf("%f",&xv);
s=0;
for(j=0;j<n;j++)
{
p1=y[j];
p2=1;
for(i=0;i<n;i++)
{
if(i!=j)
{
p1=p1*(xv-x[i]);
p2=p2*(x[j]-x[i]);
}
}
s=s+(p1/p2);
}
printf("The value of y is:%f\n",s);
printf("\nDo you want to continue(y/n):");
if('y'==getch())
goto label;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -