/*
Program to implement NEWTON'S BACKWARD METHOD OF INTEROLATION.
----------------------------------------
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<conio.h>
void main()
{
int n; // no. of terms.
int i,j,k; // Loop variables
float mx[10]; // 'X' array limit 9
float my[10]; // 'Y' array limit 9
float x; // User Query for what value of X
float x0=0; //
float y0; // Value coressponding to x0.
float sum=0; // Calculated value for coressponding X.
float h; // Calc. Section
float fun=0; //
float p; // Calc. Section
float diff[20][20]; // to store Y
float y1,y2,y3,y4; // Formulae variables.
clrscr();
// Input section.
printf("\t\t !! NEWTON'S GREGORY BACKWARD INTERPOLATION FORMULA !! ");
printf("\n\n Enter the no. of terms -> ");
scanf("%d",&n);
// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
{
printf("\n Enter the value of x%d -> ",i+1);
scanf("%f",&mx[i]);
}
// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
{
printf("\n Enter the value of y%d -> ",i+1);
scanf("%f",&my[i]);
}
// Inputting the required value quarry
printf("\n\n Enter the value of x for ");
printf("\n which u want the value of y -> ");
scanf("%f",&x);
// Calculation and processing section.
h=mx[1]-mx[0];
for(i=0;i<n-1;i++)
diff[i][1]=my[i+1]-my[i];
for(j=2;j<=4;j++)
for(i=0;i<n-j;i++)
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
i=0;
while(!mx[i]>x)
i++;
x0=mx[i];
sum=0;
y0=my[i];
fun=1;
p=(x-x0)/h;
sum=y0;
for(k=1;k<=4;k++)
{
fun=(fun*(p-(k-1)))/k;
sum=sum+fun*diff[i][k];
}
// Outut Section
printf("\n When x = %6.4f , y = %6.8f",x,sum);
// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !! ");
getch();
}
i need a pagination,fun with prime program.
ReplyDeletequickly