Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     double x;
  9.     cout << "Imput x from -1 to 1 \n";
  10.     cin >> x;
  11.    
  12.     if (x <= -1 || x > 1) {
  13.         cout << "Wrong number ";
  14.         return 0;
  15.     }
  16.    
  17.     int MaxIter = 1000;
  18.     double eps = 1e-4;
  19.     bool flag = true;
  20.    
  21.     double a = x;
  22.     double s = a;
  23.     for (int i = 1; fabs(a) > eps; i++) {
  24.         a *= -x;
  25.         s += a / (i + 1);
  26.         if (i > MaxIter) {
  27.             flag = false;
  28.             break;
  29.         }
  30.     }
  31.     if (flag) {
  32.         cout << "s=" << s << "\tln(" << x << "+1)=" << log(x+1);
  33.     } else {
  34.         cout << "Series diverges";
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement