Search:

Submit Article

# LAGRANGE'S INTERPOLATION METHOD FOR FINDING X

Posted By: Holly Brown     Category: C Programming     Views: 5055

## Code for LAGRANGE'S INTERPOLATION METHOD FOR FINDING X in C Programming

```#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10],temp=1,f[10],sum,p;
int i,n,j,k=0,c;
clrscr();
printf("\nhow many record you will be enter: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n\nenter the value of x%d: ",i);
scanf("%f",&x[i]);
printf("\n\nenter the value of f(x%d): ",i);
scanf("%f",&y[i]);
}
printf("\n\nEnter f(x) for finding x: ");
scanf("%f",&p);

for(i=0;i<n;i++)
{
temp = 1;
k = i;
for(j=0;j<n;j++)
{
if(k==j)
{
continue;
}
else
{
temp = temp * ((p-y[j])/(y[k]-y[j]));
}
}
f[i]=x[i]*temp;
}

for(i=0;i<n;i++)
{
sum = sum + f[i];
}
printf("\n\n* * * x = %f * * *",sum);
getch();
}

/*______________________________________         OUT PUT______________________________________how many record you will be enter: 4enter the value of x0: 20enter the value of f(x0): 0.342enter the value of x1: 25enter the value of f(x1): 0.423enter the value of x2: 30enter the value of f(x2): 0.500enter the value of x3: 35enter the value of f(x3): 0.650Enter f(x) for finding x: 0.390* * * x = 22.840574 * * **/```
Share:

Didn't find what you were looking for? Find more on LAGRANGE'S INTERPOLATION METHOD FOR FINDING X Or get search suggestion and latest updates.

 Holly Brown author of LAGRANGE'S INTERPOLATION METHOD FOR FINDING X is from London, United Kingdom. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!