Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 2

1.Write a program to find the value of y at any interpolating point x, given by the user through Lagranges Interpolation formula.

Program:#include<stdio.h> #include<conio.h> void main() { float x[10],y[10],x1,prod,sum=0.0; int i,j,n; clrscr(); printf("\nEnter the number of values: "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter the value of x[%d] and y[%d]: ",i,i); scanf("%f %f",&x[i],&y[i]); } printf("\nEnter the interpolating point: "); scanf("%f",&x1); for(i=0;i<n;i++) { prod=1.0; for(j=0;j<n;j++) { if(i==j) continue; else prod*=(x1-x[j])/(x[i]-x[j]); } sum+=y[i]*prod; } printf("\nThe value of y at x = %f is %f",x1,sum); getch(); }

Output:Enter the number of values: 5 Enter the value of x[0] and y[0]: 93.011.38 Enter the value of x[1] and y[1]: 96.212.80 Enter the value of x[2] and y[2]: 100.0 Enter the value of x[3] and y[3]: 104.2 Enter the value of x[4] and y[4]: 108.7 Enter the interpolating point: 102 The value of y at x = 102.000000 is 15.793629 14.70 17.07 19.91

You might also like