Code for Newton’s forward interpolation in C

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

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
main()
{
  float x[20],y[20],f,s,h,d,p;
  int j,i,n;
  printf(“enter the value of n :”);
  scanf(“%d”,&n);
  printf(“enter the elements of x:”);
  for(i=1;i<=n;i++)
   {
        scanf(“%f”,&x[i]);
         }
                   printf(“enter the elements of y:”);
               for(i=1;i<=n;i++)
               {
              scanf(“%f”,&y[i]);                  
                                }
  h=x[2]-x[1];
  printf(“Enter the value of f:”);
  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-i);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=%6.5f THe value is %6.5f”,f,d);
 getch();
}

You might be also interested in :

About these ads

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s