Advertisement
themlgyo

Вычисление суммы бескряда

Sep 20th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     setlocale(LC_ALL, "RUSSIAN");
  9.     const int MaxIterationCount = 500;
  10.     double x, eps; int n;
  11.     cout << "Введите аргумент: ";
  12.     cin >> x;
  13.     cout << " " << endl;
  14.     cout << endl << "Введите точность: ";
  15.     cin >> eps;
  16.     cout << endl;
  17.     bool done = true;
  18.     double y = x, ch = x;
  19.     for (n = 1; fabs(ch) > eps; n++)
  20.     {
  21.         ch *= x*x / ((2 * n + 1)*(2 * n + 2));
  22.         y += ch;
  23.         if (n > MaxIterationCount) {
  24.             done = false; break;
  25.         }
  26.     }
  27.     cout << " " << endl;
  28.     if (done) cout << "Значение функции: " << y << endl;
  29.     else cout << "Ошибка: ряд расходится!" << endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement