Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- double calc(int& n, double &xm1) {
- return (n % 2 == 0) ? -xm1 / n : xm1 / n;
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- int n = 1, precision = 0;
- const double h = 0.1, a = 0.5, b = 1.5;
- double x = a, e = 0, fx, s = 0, xm1;
- while (e <= 0) {
- cout << "Введите значение e (e > 0): ";
- cin >> e;
- }
- precision = -((int)log10(e) - 1); // Установка точности для вывода
- e = pow(10, -precision) / 2.000000000000001; // Упрощение E (0.008 -> 0.001 -> 0.000499..9)
- cout << " № X Fx n\n";
- while (x <= b + h) {
- xm1 = x - 1;
- s = 0;
- int ns = 10;
- fx = e + 1;
- do{
- xm1 *= x - 1;
- fx = calc(ns, xm1);
- s += fx;
- ns++;
- }while (abs(fx) > e);
- cout << setw(3) << n
- << setw(11) << right << fixed << setprecision(1) << x
- << setw(13) << right << fixed << setprecision(precision) << s
- << setw(4) << ns << endl;
- x += h;
- n++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement