Advertisement
Kentoo

K#1

Dec 18th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #define _USE_MATH_DEFINES
  4. #include "math.h"
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. double receq(double t, double f, double x, double e, int i) {
  10.     double t1 = t * pow(-1, i + 1) * pow(x, 2) * log(1 + 2 * i) / (4 * log(1 + 2 * (i - 1)));
  11.     f += t1;
  12.     if (abs(t1) <= e) {
  13.         return f;
  14.     }
  15.     else {
  16.         return receq(t1, f, x, e, i + 1);
  17.     }
  18. }
  19.  
  20. void main()
  21. {
  22.     SetConsoleCP(1251);
  23.     SetConsoleOutputCP(1251);
  24.     double e;
  25.     cout << "Введите точность вычисления" << endl;
  26.     cin >> e;
  27.     double x;
  28.     cout << "Введите x" << endl;
  29.     cin >> x;
  30.     double s = 0, t = 1;
  31.     int N = 1;
  32.     while (abs(t) > e) {
  33.         t = pow(-1, N + 1) * pow(x, 2 * N) * log(1 + 2 * N) / (4 * pow(N, 2));
  34.         s += t;
  35.         N++;
  36.     }
  37.     cout.precision(15);
  38.     cout << "Сумма ряда через общую формулу = " << s << endl;
  39.     double r, k1 = pow(x, 2) * log(3) / 4;
  40.     r = receq(k1, k1, x, e, 2);
  41.     cout.precision(15);
  42.     cout << "Сумма ряда через смешанный способ = " << r << endl;
  43.     system("pause");
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement