#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float x0,n,x[300],f[300],sum=0.0;
for m=1.0;
printf("\n input number of data points");
scanf("%f",&n);
for(int i=1;i<=n;i++)
{
printf("\n Enter the data and value of function at that point");
scanf(“%f %f” ,&x[i],&f[i]);
}
printf("\n input x at which interpolation is required");
scanf("%f",&x0);
for(i=1;i<=n;i++)
{
m=0.1;
for(int j=1;j<=n;j++)
{
if(i!=j)
m=m*(x0-x[j])/(x[i]-x[j]);
}
sum=sum+m*f[i];
}
printf("\n %f",sum);
getch();
}
No comments:
Post a Comment