You are on page 1of 3

Program:

#include​<stdio.h>
#include​<conio.h>
#include​<math.h>
int​ main()
{
int​ n,i;
float​ Y,t,X,h,p,x[50],y[50],d1y[50],d2y[50],d3y[50],d4y[50],d5y[50],d6y[50];
printf(​"enter the number of values: "​);
scanf(​"%d"​,&n);
for​(i=0;i<n;++i)
{printf(​"enter the next value of x: "​);
scanf(​"%f"​,&x[i]);
printf(​"value of y= "​);
scanf(​"%f"​,&y[i]);
}
printf(​"enter the value of x for which corresponding y should be found: "​);
scanf(​"%f"​,&X);
h=x[1]-x[0];
p=(X-x[0])/h;
for​(i=0;i<n-1;++i)
{ d1y[i]=y[i+1]-y[i];
}
for​(i=0;i<n-2;++i)
{ d2y[i]=d1y[i+1]-d1y[i];
}

for​(i=0;i<n-3;++i)
{d3y[i]=d2y[i+1]-d2y[i];
}

for​(i=0;i<n-4;++i)
{ d4y[i]=d3y[i+1]-d3y[i];
}
for​(i=0;i<n-5;++i)
{ d5y[i]=d4y[i+1]-d4y[i];
}
for​(i=0;i<n-6;++i)
{d6y[i]=d5y[i+i]-d5y[i];
}

Y=y[0]+p*d1y[0]+p*(p-1)/2*d2y[0]+p*(p-1)*(p-2)/6*d3y[0]+p*(p-1)*(p-2)*(p-3)/24*d4y[0]
+p*(p-1)*(p-2)*(p-3)*(p-4)/120*d5y[0];
printf(​"\n the value of p is %f"​,p);
printf(​"\n"​);
printf(​"D1:"​);
for​(i=0;i<n-1;++i)
printf(​" %f"​,d1y[i]);
printf(​"\n \n"​);
printf(​"D2:"​);
for​(i=0;i<n-2;++i)
printf(​" %f "​,d2y[i]);
printf(​"\n \n"​);
printf(​"D3:"​);
for​(i=0;i<n-3;++i)
printf(​" %f"​,d3y[i]);
printf(​"\n \n"​);
printf(​"D4:"​);
for​(i=0;i<n-4;++i)
printf(​" %f"​,d4y[i]);
printf(​"\n \n"​);
printf(​"D5:"​);
for​(i=0;i<n-5;++i)
printf(​" %f"​,d5y[i]);
printf(​"\n \n"​);

printf(​"\n answer is =%f "​,Y);


getch();
return​ 0;
}

Output:

enter the number of values: 7

enter the next value of x: 100

value of y= 10.63

enter the next value of x: 150

value of y= 13.03

enter the next value of x: 200

value of y= 15.04

enter the next value of x: 250

value of y= 16.81

enter the next value of x: 300

value of y= 18.42

enter the next value of x: 350

value of y= 19.90

enter the next value of x: 400


value of y= 21.27

enter the value of x for which corresponding y should be found: 218

the value of p is 2.360000

D1: 2.400000 2.010000 1.770000 1.610001 1.480000 1.370001

D2: -0.389999 -0.240001 -0.159999 -0.130001 -0.109999

D3: 0.149999 0.080002 0.029998 0.020002

D4: -0.069997 -0.050004 -0.009995

D5: 0.019993 0.040009

answer is =15.699373

You might also like