You are on page 1of 1

#include<stdio.

h>
#include<conio.h>
#include<math.h>
main()
{
int n,i,j;
float u[100],v[100],X,y,nr,dr;
X=0;
y=0;
clrscr();
printf("enter the no. of term–");
scanf("%d", &n);
printf("enter the value in the form of x–\n");
for(i = 0; i < n; i++)
{
printf("enter the value of x%d=\n", i+1);
scanf("%f", &u[i]);
}
printf("enter the value in the form of y\n");
for(i = 0; i < n; i++)
{
printf("enter the value of y%d=\n",i+1);
scanf("%f", &v[i]);
}
printf("enter the value of X for which Interpolation required=");
scanf("%f",&X);
for(i = 0; i < n; i++)
{
nr = 1;
dr = 1;
for(j = 0; j < n; j++)
{
if(j!=i)
{
nr=nr*(X-u[j]);
dr=dr*(u[i]-u[j]);
}
}
y = y+(nr/dr)*v[i];
}
printf("when X = %f, y = %f", X, y);
getch();
}

You might also like