#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10][10],sum,p,u,temp,temp1;
int i,n,j,k=0,f,m,l=0;
float fact(int);
clrscr();
printf("\nhow many record you will be enter: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n\nenter the value of x%d: ",i);
scanf("%f",&x[i]);
printf("\n\nenter the value of f(x%d): ",i);
scanf("%f",&y[k][i]);
}
printf("\n\nEnter X for finding f(x): ");
scanf("%f",&p);
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
y[i][j]=y[i-1][j+1]-y[i-1][j];
}
}
printf("\n_______________________________________________________________\n");
printf("\n x(i) y(i)");
for(i=1;i<n;i++)
{
printf(" y%d(i)",i);
}
printf("\n_______________________________________________________________\n");
for(i=0;i<n;i++)
{
printf("\n %.4f",x[i]);
for(j=0;j<n-i;j++)
{
printf(" ");
printf("%.4f",y[j][i]);
}
printf("\n");
}
i=0;
do
{
if(x[i]==p)
k=1;
else
i++;
}while(k != 1);
f=i;
n=n-f;
sum=0;
for(i=1;i<n;i++)
{
if(l==0)
{
sum = sum + (y[i][f]/i);
l=1;
}
else
{
sum = sum - (y[i][f]/i);
l=0;
}
}
sum = sum/(x[1]-x[0]);
printf("\n\n f(%.2f) = %f ",p,sum);
getch();
}
/*
______________________________________
OUT PUT
______________________________________
how many record you will be enter: 7
enter the value of x0: 1.0
enter the value of f(x0): 2.7183
enter the value of x1: 1.2
enter the value of f(x1): 3.3201
enter the value of x2: 1.4
enter the value of f(x2): 4.0552
enter the value of x3: 1.6
enter the value of f(x3): 4.9530
enter the value of x4: 1.8
enter the value of f(x4): 6.0496
enter the value of x5: 2.0
enter the value of f(x5): 7.3891
enter the value of x6: 2.2
enter the value of f(x6): 9.0250
Enter X for finding f(x): 1.2
_______________________________________________________________
x(i) y(i) y1(i) y2(i) y3(i) y4(i) y5(i) y6(i)
_______________________________________________________________
1.0000 2.7183 0.6018 0.1333 0.0294 0.0067 0.0013 0.0001
1.2000 3.3201 0.7351 0.1627 0.0361 0.0080 0.0014
1.4000 4.0552 0.8978 0.1988 0.0441 0.0094
1.6000 4.9530 1.0966 0.2429 0.0535
1.8000 6.0496 1.3395 0.2964
2.0000 7.3891 1.6359
2.2000 9.0250
f(1.20) = 3.320317
*/