Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void main()
- {
- double ax[50],ay[50],diff[50][50];
- double x,h,yp,nr=1,p,dr=1;
- int n,i,j;
- printf("enter the nuber of known data values:");
- scanf("%d",&n);
- printf("enter the values of x and y respectively\n");
- for(i=0;i<n;i++)
- {
- printf("x%d=",i);
- scanf("%lf",&ax[i]);
- printf(" y%d=",i);
- scanf("%lf",&ay[i]);
- printf("\n");
- }
- printf("enter the value of x to find y\n");
- scanf("%lf",&x);
- h=ax[1]-ax[0];
- for(i=0;i<n;i++)
- diff[i][0]=ay[i+1]-ay[i];
- for(j=1;j<(n-1);j++)
- {
- for(i=0;i<=(n-j);i++)
- diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
- }
- yp=ay[n-1];
- i=n-1;
- p=(x-ax[n-1])/h;
- for(j=1;j<(n-1);j++)
- {
- nr=nr*(p+j-1);
- dr=dr*j;
- yp=yp+(nr/dr)*diff[i-1][j-1];
- i--;
- }
- printf("For x = %.4lf y = %.4lf\n",x,yp);
- }
- OUTPUT:
- enter the nuber of known data values:5
- enter the values of x and y respectively
- x0=200
- y0=15.04
- x1=250
- y1=16.81
- x2=300
- y2=18.42
- x3=350
- y3=19.9
- x4=400
- y4=21.27
- enter the value of x to find y
- 218
- For x = 218.0000 y = 15.7021
- Press any key to continue
Add Comment
Please, Sign In to add comment