Code for Newton’s Backward interpolation in C

C code to implement Newton’s Backward  interpolation .  Compiled in DEV C++

website_caption1

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
main()
{
      float x[20],y[20],f,s,d,h,p;
      int j,i,k,n;
      printf("enter the value of the elements :");
      scanf("%d",&n);
      printf("enter the value of x: nn");
      for(i=1;i<=n;i++)
      {
                       scanf("%f",&x[i]);
                       }
             printf("enter the value of y: nn");
      for(i=1;i<=n;i++)
      {
                       scanf("%f",&y[i]);
                       }     
                       h=x[2]-x[1];
           printf("enter the searching point f:");                  
scanf("%f",&f);
s=(f-x[n])/h;
d=y[n];
p=1;
for(i=n,k=1;i>=1,k<n;i--,k++)
{
                 for(j=n;j>=1;j--)
                 {
                                 y[j]=y[j]-y[j-1];
                                 }
                                 p=p*(s+k-1)/k;
                                 d=d+p*y[n];
}
printf("for f=%f ,ans is=%f",f,d);
getch();
}

 website_caption1

You might be also interested in :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s