Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <cmath>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     setlocale(LC_ALL, "Russian");
  10.     double accurCalc;
  11.     cout << "Введите точность вычислений: " << endl;
  12.     cin >> accurCalc;
  13.  
  14.     while (accurCalc < 0.000001 || accurCalc > 1) {
  15.         cout << "Введено некорректное или слишком маленькое значение!" << endl << "Введите точность вычислений: " << endl;
  16.         cin >> accurCalc;
  17.     }
  18.  
  19.     random_device generator;
  20.     uniform_real_distribution<double> distribution(-1, 0.999999);
  21.     double x = distribution(generator);
  22.     cout << "На интервале вещественных чисел [-1; 1) выбран x, равный: " << x << "\n";
  23.     double sum = 0.0;
  24.     double a = x;
  25.     int i = 1;
  26.     while (abs(a) >= accurCalc) {
  27.         sum -= a;
  28.         a *= (x * i / (i + 1));
  29.         i++;
  30.     }
  31.    
  32.     double rezulFun = log(1 - x);
  33.     double diff = abs(sum - rezulFun);
  34.     cout << setprecision(ceil(log10(1 / accurCalc))) << "Результат функции: " << rezulFun << endl <<
  35.         "Результат просчета ряда: " << sum << endl;
  36.     cout << "Погрешность составляет: " << diff << endl;
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement