Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- double accurCalc;
- cout << "Введите точность вычислений: " << endl;
- cin >> accurCalc;
- while (accurCalc < 0.000001 || accurCalc > 1) {
- cout << "Введено некорректное или слишком маленькое значение!" << endl << "Введите точность вычислений: " << endl;
- cin >> accurCalc;
- }
- random_device generator;
- uniform_real_distribution<double> distribution(-1, 0.999999);
- double x = distribution(generator);
- cout << "На интервале вещественных чисел [-1; 1) выбран x, равный: " << x << "\n";
- double sum = 0.0;
- double a = x;
- int i = 1;
- while (abs(a) >= accurCalc) {
- sum -= a;
- a *= (x * i / (i + 1));
- i++;
- }
- double rezulFun = log(1 - x);
- double diff = abs(sum - rezulFun);
- cout << setprecision(ceil(log10(1 / accurCalc))) << "Результат функции: " << rezulFun << endl <<
- "Результат просчета ряда: " << sum << endl;
- cout << "Погрешность составляет: " << diff << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement