Thursday, 2 November 2017

C Programme for Newton Forward Interpolation

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j,n;
float x[20],y[20],f,s,h,d,p;
clrscr();
printf("enter the value of n:");
scanf("%d",&n);
printf("enter the element of x:");
for(i=1;i<=n;i++)
{
scanf("%f",&x[i]);
}
printf("enter the element of y:");
for(i=1;i<=n;i++)
{
scanf("%f",&y[i]);
}
h=x[2]-x[1];
printf("enter the value of x to find value of y:");
scanf("%f",&f);
s=(f-x[1])/h;
p=1;
d=y[1];
for(i=1;i<=(n-1);i++)
{
for(j=1;j<=(n-1);j++)
{
y[j]=y[j+1]-y[j];
}
p=p*(s-i+1)/i;
d=d+p*y[1];
}
printf("for the value of x=%fthe value is:%f",f,d);
getch();
}

Input/Output:


No comments:

Post a Comment