Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- double x[100];
- double y[100];
- double f(int p,int y,double x1)
- {
- double temp=1;
- for(int i=0;i<y;i++)
- {
- if(i!=p)
- {
- temp*=(x1-x[i]);
- }
- }
- return temp;
- }
- double g(int s,int n)
- {
- double q=x[s],temp=1;
- for(int i=0;i<n;i++)
- {
- if(i!=s)
- {
- temp*=(q-x[i]);
- }
- }
- return temp;
- }
- int main()
- {
- int n;
- double x1,sum=0;
- cout<<"enter the total value of x and y:";
- cin>>n;
- for(int i=0;i<n;i++)
- { cout<<"enter the element of x:";
- cin>>x[i];
- cout<<"enter the element of y:";
- cin>>y[i];
- }
- cout<<"enter the desired value:";
- cin>>x1;
- for(int i=0;i<n;i++)
- {
- sum+=(f(i,n,x1)*y[i])/g(i,n);
- }
- cout<<sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement