/*Linear Interpolation*/
#include<stdio.h>
#include<conio.h>
void main()
{
float x1,x0,x,f0,f1,f;
clrscr();
puts("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
puts("Program for Linear Interpolation");
puts("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"-);
printf("Enter the values of x0 and f(x0)\n");
scanf("%f %f",&x0,&f0);
puts("----------------------------------------");
printf("Enter the values of x1 and f(x1)");
scanf("%f %f",&x1,&f1);
puts("----------------------------------------");
printf("Enter the values of x ");
scanf("%f",&x);
puts("----------------------------------------");
f=f0+((f1-f0)*(x-x0)/(x1-x0));
printf("%f",f);
puts("\n--------------------------------------");
getch();
}
Output:-
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Program for Linear Interpolation
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Enter the values of x0 and f(x0)
1 0
----------------------------------------
Enter the values of x1 and f(x1)
6 1.791759
----------------------------------------
Enter the values of x
2
----------------------------------------
0.358352
--------------------------------------
No comments:
Post a Comment