Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<stdlib.h>
- using namespace std;
- int main(){
- float x[30], y[30],X, p, sum=0;
- int n;
- cout<<"Enter the no of data you want to input: ";
- cin>>n;
- for(int i=0;i<n;i++) {
- cout<<"X ["<<i+1<<"] :";
- cin>>x[i];
- cout<<"Y ["<<i+1<<"] :";
- cin>>y[i];
- }
- cout<<"Enter the value for x: ";
- cin>>X;
- for(int i=0;i<n;i++){
- p=1;
- for(int j=0;j<n;j++){
- if (i != j){
- p=p*((X-x[j])/(x[i]-x[j]));
- }
- }
- sum=sum+(p*y[i]);
- }
- cout<<endl<<"The root is: "<<sum;
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement