Backward Difference Table Generation Using C Programming

While interpolating intermediate value of dependent variable for equi-spaced data of independent variable, at the end of the table, Newton's Backward Interpolation formula is used. This method relies on Backward Difference Table is used. In this article, we are going to generate backward difference table using c programming language.

Program


#include<stdio.h>
#include<conio.h>

int main()
{
 float x[20], y[20][20];
 int i,j, n;
 clrscr();
 /* Input Section */
 printf("Enter number of data?\n");
 scanf("%d", &n);
 printf("Enter data:\n");
 for(i = 0; i < n ; i++)
 {
  printf("x[%d]=", i);
  scanf("%f", &x[i]);
  printf("y[%d]=", i);
  scanf("%f", &y[i][0]);
 }

 /* Generating Backward Difference Table */
 for(i = 1; i < n; i++)
 {
  for(j = n-1; j > i-1; j--)
  {
   y[j][i] = y[j][i-1] - y[j-1][i-1];
  }
 }

 /* Displaying Forward Difference Table */
 printf("\nBACKWARD DIFFERENCE TABLE\n\n");
 for(i = 0; i < n; i++)
 {
  printf("%0.2f", x[i]);
  for(j = 0; j <= i ; j++)
  {
   printf("\t%0.2f", y[i][j]);
  }
  printf("\n");
 }

 getch(); /* Holding Screen */
 return 0;
}

Backward Difference Table C Output

Enter number of data?
4
Enter data:
x[0]=0
y[0]=1
x[1]=1
y[1]=2
x[2]=2
y[2]=1
x[3]=3
y[3]=10

BACKWARD DIFFERENCE TABLE

0.00    1.00
1.00    2.00    1.00
2.00    1.00    -1.00   -2.00
3.00    10.00   9.00    10.00   12.00

Recommended Readings

  1. Forward Difference Table Generation Using C Programming
  2. Forward Difference Table Generation Using C++ with Output
  3. Backward Difference Table Generation Using C Programming
  4. Backward Difference Table Generation Using C++ with Output