/*
Lagranges formula
x: 30 35 45 55
y: 148 196 68 34
Compute::f(40)=?
*/
#include<conio.h>
#include<stdio.h>
#define n 4
void main()
{
float f,x[n],y[n],xf,fx;
int j,i;
for(i=0;i<n;i++)
{
printf("\nEnter x[%d] & y[%d]",i+1,i+1);
scanf("%f%f",&x[i],&y[i]);
}
printf("\nEnter x");
scanf("%f",&xf);
fx=0;
for(i=0;i<n;i++)
{
f=1;
for(j=0;j<n;j++)
{
if(i!=j)
f=f*((xf-x[j])/(x[i]-x[j]));
}
fx=fx+(f*y[i]);
}
printf("\nResult %f",fx);
getch();
}
0 Comments