Advertisement
Risonna

lab3_n2beta4

Nov 19th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include<math.h>
  2. #include<iostream>
  3. #define pi acos(-1.0)
  4. using namespace std;
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "RUS");
  8.     double x, b, h, a, y, i, s0, s1, e, p;
  9.     e = 1.4e-1;
  10.     b = pi;
  11.     h = pi / 25;
  12.     a = pi / 5;
  13.     i = 1;
  14.     x = a;
  15.     s0 = (pow(-1, i) * cos(i * x)) / (i * i);
  16.     s1 = (pow(-1, (i + 1)) * cos((i + 1) * (x + h))) / ((i + 1) * (i + 1));
  17.     for (x = a; x <= b; x = x + h)
  18.     {
  19.         i++;
  20.         if (fabs(s1 - s0) > e)
  21.         {
  22.             s0 += (pow(-1, i) * cos(i * x)) / (i * i); cout << "s0=" << s0<<"\n";
  23.             s1 += (pow(-1, i) * cos(i * x)) / (i * i); cout << "s1=" << s1<<"\n";
  24.             y = ((x * x) - ((pi * pi) / 3));
  25.             p = fabs(s0 - y);
  26.             cout << "p=" << p << "\n";
  27.             cout << "e=" << e << "\n";
  28.         }
  29.         else
  30.         {
  31.             break;
  32.         }
  33.     }
  34.     cout << "Сумма равна" << s0;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement