Newton’s forward Interpolation Formula.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<alloc.h>
int main (void)
{
int k,i,n;
float *x,*y,u,h,term=1,nff,x1;
clrscr();
printf("Enter the no. of terms:");
scanf("%d",&n);
x=(float*)malloc(n*sizeof(float));
y=(float*) malloc(n*sizeof(float));
printf("\nEnter the equi spaced x values for the function:");
for(i=0;i<n;i++)
scanf("%f",&x[i]);
printf("\nEnter the corresponding y values:");
for(i=0;i<n;i++)
scanf("%f",&y[i]);
h=x[1]-x[0];
printf("\nEnter the x value for which y will be calcuted:");
scanf("%f",&x1);
u=(x1-x[0])/h;
nff=y[0];
for(k=0;k<n-1;k++)
{
term=term*(u-k)/(k+1);
for(i=0;i<n-1-k;i++)
y[i]=y[i+1]-y[i];
nff=nff+(term*y[0]);
}
printf("\nThe value of y(x) corresponding to particular x is: %f",nff);
getch();
free(x);
free(y);
return 0;
}
