Advertisement
DasShelmer

5.3.19

Oct 15th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.     setlocale(LC_ALL, "Russian");
  7.     int i = 1, precision = 0;
  8.     double e = -1, s = 0, a = 1.0 / 3.0;
  9.     while (e <= 0) {
  10.         cout << "Введите значение e (e > 0): ";
  11.         cin >> e;
  12.     }
  13.     precision = -((int)log10(e) - 1); // Установка точности для вывода
  14.     e = pow(10, -precision) / 2.000000000000001; // Упрощение E (0.008 -> 0.001 -> 0.000499..9)
  15.     while(a > e) {
  16.         a = pow(-1, i + 1) / pow(3, 2 * i - 1);
  17.         s += a;
  18.         i++;
  19.     }
  20.     printf("P: %.*lf\n", precision, s);
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement