# Write C program to implement the `Newton- Gregory forward interpolation`.

#### Algorithm:

```Step1:    START
Step3:    for i = 0 to (n-1) do read xi, yi
Step5:    h ← xi-x0
Step6:    p ← (x - xo)/n
Step7:    for j = 0 to n-2 do
Δ1yj ← yj + 1 - Δi - 1
Step8:    k ← n - 2
Step9:    for i = 2 to (n - 1) do
Step9.1:  k ← k - 1
Step9.2:  for j = 0 to k do
Δiyj ← Δi - 1 yj + 1 - Δi - 1yj
Step10:   Sumy ← y0
Step11:   Pvalue ← 1
Step12:   Fact value ← 1
Step13:   for l = 1 to (n - 1) do
Step13.1: Pvalue ← pvalue x (p - (l - 1))
Step13.2: factvalue ← factvaluex1
Step13.3: term ← (pvalue x Δly) / factvalue
Step13.4: Sumy ← Sumy + term
Step14:   Print x, SUMY
Step15:   STOP```

#### Flowchart: #### Program:

```#include<stdio.h>
#include<math.h>
main()
{
int i, j, n, k, l;
float sumy, h, term, p, z, pvalue;
float x, y, d, factvalue;
printf(“enter the value of n”);
scanf(“%d”, &n);
printf(“enter %d values for x, y \n”, n);
for(i = 0; i < n; i++)
scanf(“%f %f”, &x[i], &y[i]);
printf(“\n enter z”);
scanf(“%f”, &z);
h = x – x;
p = (z - x )/ h;
for(j = 0; j < n-2; j++)
d[i][j] = y[j + 1] – y[j];
k = n-2;
for(i = 2; i < n; i++)
{
k++;
for(j = 0; j <= k; j++)
d[i][j] = d[i - 1][j + 1] – d[i - 1][j];
}
for(l = 1; l < n; l++)
{
pvalue *= (p - (l - 1));
factvalue *= 1;
term = pvalue * d[l] / factvalue;
sumy += term;
}
printf(“\n y value at z = %f is %f”, z, sumy);
}```

#### Input & Output:

```enter n 7
enter 7 data values for x, y
1921 35
1931 42
1941 58
1951 84
1961 120
1971 165
1981 220
enter z 1925
y value at z = 1925.000000 is 36.756710```
• Updated
Oct 21, 2014
• Views
17,050
You May Like