nvnnaidenov

Zad23

Sep 22nd, 2021
885
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int i;
  8.     double x;
  9.     double eps;
  10.     double x1;
  11.     double s;
  12.  
  13.     cout << "x = ";
  14.     cin >> x;
  15.     if(!cin)
  16.     {
  17.         cout << "Error, bad input!";
  18.         return 1;
  19.     }
  20.     cout << "eps = ";
  21.     cin >> eps;
  22.     if(!cin)
  23.     {
  24.         cout << "Error, bad input!";
  25.         return 1;
  26.     }
  27.     if(eps <= 0)
  28.     {
  29.         cout << "Incorrect input!";
  30.         return 1;
  31.     }
  32.  
  33.     i = 1;
  34.     x1 = 1;
  35.     s = 1;
  36.  
  37.     while(fabs(x1) >= eps)
  38.     {
  39.         x1 = x1 * x / i;
  40.         s = s + x1;
  41.         i++;
  42.     }
  43.  
  44.     cout << "s = " << s << endl;
  45.  
  46.     return 0;
  47. }
RAW Paste Data