Advertisement
TheMagnusRex

6.2

Jan 15th, 2021
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n; //
  7.     double xp; //
  8.     double yp=0.0;
  9.     cout<<"n=";
  10.     cin>>n;
  11.     double x[n];
  12.     double y[n];
  13.     for (int l=0;l<n;l++){
  14.         cout<<"x_"<<l<<" || y_"<<l<<endl;
  15.         cin>>x[l]>>y[l];
  16.     }
  17.         for (int l=0;l<n;l++){
  18.         cout<<"x_"<<l<<"="<<x[l]<<" || y_"<<l<<"="<<y[l]<<endl;
  19.     }
  20.     cout<<"approximation point:xp=";
  21.     cin>>xp;
  22.     double P;//
  23.     for (int i = 0;i<n;i++){
  24.         P=1.0;
  25.         for (int k=0;k<n;k++){
  26.             if(i!=k){
  27.                 P*=(xp-x[k])/(x[i]-x[k]);
  28.             }
  29.         }
  30.         yp+=P*y[i];
  31.     }
  32.     cout<<"xp="<<xp<<endl;
  33.     cout<<"yp="<<yp<<endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement