#include<iostream>
using namespace std;
int main()
{
float x[10],y[10],x1,y1=0.0;
int i,j,n;
cout<<"Enter No of terms in table: ";
cin>>n;
cout<<"Enter X and Corresponding Y\n";
cout<<"X Y\n";
for(i=0;i<n;i++)
cin>>x[i]>>y[i];
cout<<"Enter the X for which Y to be Found: ";
cin>>x1;
float s,t;
for(i=0;i<n;i++)
{
s=1;
t=1;
for(j=0;j<n;j++)
{
if(j!=i)
{
s=s*(x1-x[j]);
t=t*(x[i]-x[j]);
}
}
y1=y1+((s/t)*y[i]);
}
cout<<"\nFor X="<<x1<<"\tCorrecponding "<<"Y="<<y1;
}
using namespace std;
int main()
{
float x[10],y[10],x1,y1=0.0;
int i,j,n;
cout<<"Enter No of terms in table: ";
cin>>n;
cout<<"Enter X and Corresponding Y\n";
cout<<"X Y\n";
for(i=0;i<n;i++)
cin>>x[i]>>y[i];
cout<<"Enter the X for which Y to be Found: ";
cin>>x1;
float s,t;
for(i=0;i<n;i++)
{
s=1;
t=1;
for(j=0;j<n;j++)
{
if(j!=i)
{
s=s*(x1-x[j]);
t=t*(x[i]-x[j]);
}
}
y1=y1+((s/t)*y[i]);
}
cout<<"\nFor X="<<x1<<"\tCorrecponding "<<"Y="<<y1;
}
No comments:
Post a Comment