You are on page 1of 6

QUESTION -Create a Forward Difference Table

Year 1901. 1911. 1921. 1931. 1941. 1951. 1961.


Pop. 36. 43. 50. 56. 62. 68. 79
CODE –
#include<iostream>
Using namespace std;
Int main()
{
Cout<<”Newton Forward Interpolation Method”<<endl;
Int n,I,j;
Cout<<”\nEnter no of data points: “;
Cin>>n;
Float a[n][n+1];
For (i=0;i<n;++i){
Cout<<”Enter the year:\n”;
Cin>>a[i][0];
}
For (i=0;i<n;++i){
Cout<<”Enter population in year “<<a[i][0]<<”\n”;
Cin>>a[i][1];
}
For (j=2;j<(n+1);++j){
For (i=0;i<(n-j+1);++i)
A[i][j]=a[i+1][j-1]-a[i][j-1];
}
Cout<<”Forward Difference Table for year vs
population\n”;
For (i=0;i<n;++i){
For (j=0;j<((n+1)-i);++j){
Cout<<a[i][j]<<”\t”;
}
Cout<<”\n”;
}
Return 0;
}
OUTPUT-
Newton Forward Interpolation Method
Enter no of data points: 7
Enter the year:
1901
Enter the year:
1911
Enter the year:
1921
Enter the year:
1931
Enter the year:
1941
Enter the year:
1951
Enter the year:
1961
Enter population in year 1901
36
Enter population in year 1911
43
Enter population in year 1921
50
Enter population in year 1931
56
Enter population in year 1941
62
Enter population in year 1951
68
Enter population in year 1961
79
Forward Difference Table for year vs population
1901 36 7 0 -1 2-3 9
1911 43 7 -1 1 -1 6
1921 50 6 0 0 5
1931 56 6 0 5
1941 62 6 5
1951 68 11
1961 79
[Process completed – press Enter]

You might also like