Advertisement
Risonna

lab3_n2beta3

Nov 14th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 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, s, 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.     s = (pow(-1, i) * cos(i * x)) / (i * i);
  16.     p = (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.         p += (pow(-1, i) * cos(i * x)) / (i * i);
  21.         if (fabs(p - s) > e)
  22.         {
  23.             s += (pow(-1, i) * cos(i * x)) / (i * i);
  24.             continue;
  25.         }
  26.         else
  27.         {
  28.             break;
  29.         }
  30.         y = ((x * x) - ((pi * pi) / 3));
  31.     }
  32.         cout << "Сумма равна" << s;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement