Newton Forward Interpolation Method

Newton Forward Interpolation Method :

#include<stdio.h>
int main()
{
    int n,i,j;
    printf("Enter the value of Number of inputs");
    scanf("%d",&n);
    float x[n],y[n][n],a;
for(i=1;i<=n;i++)
     {
        printf("Enter the value of x[%d] : ",i);
        scanf("%f",&x[i]);
     }
for(i=1;i<=n;i++)
    {

        printf("Enter the value of y[%d] : ",i);
        scanf("%f",&y[i][1]);
    }
printf("Enter the value of X whose approximate value you want");
    scanf("%f",&a);
      int pc;
      pc=n;
for(i=2;i<=pc;i++)
      {
    for(j=1;j<n;j++)
          {
              y[j][i]=y[j+1][i-1]-y[j][i-1];
          }
        n--;
      }
     n=pc;
     float s,p,r,sum;
     sum=0;
     r=((a-x[1])/(x[2]-x[1]));
     for(i=2;i<=n;i++)
      {
          s=p=1;
      for(j=0;j<i-1;j++)
          {
              s=s*(r-j);
          }
      for(j=i-1;j>=2;j--)
          {
              p=p*j;
          }
          sum=(sum+((s/p)*y[1][i]));

      }
    printf("The Output Corrsponding to %f is %f",a,y[1][1]+sum);
    return 0;

}

Comments

Popular posts from this blog

Newton Backward Interpolation Formula