Advertisement
Sanlover

Untitled

Oct 23rd, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. setlocale(LC_ALL, "ru");
  8. long float eps = 0.00001;
  9. int k = 0;
  10. long float sum = 0;
  11. long float sum1;
  12.  
  13. long float fact = 1;
  14. int a = 1;
  15. long float x;
  16.  
  17. do
  18. {
  19. cin >> x;
  20. } while (x == 0);
  21.  
  22. do
  23. {
  24. sum1 = sum;
  25. double numerator = a * pow(x, 4 * k + 1); //numerator - числитель
  26. double denumerator = fact * (4 * k + 1); //denumerator - знаменатель (разделил, чтобы легче было искать ошибку)
  27. sum += numerator / denumerator;
  28. a = -a;
  29. k++;
  30. fact *= 2 * k;
  31. } while (abs(sum - sum1) > eps && isinf(sum) == 0);
  32.  
  33. cout << "Вычисление суммы закончилось на [" << k << "] элементе, сумма в этот момент = " << sum1 << endl;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement