Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<math.h>
- #include<iostream>
- #define pi acos(-1.0)
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUS");
- double x, b, h, a, y, i, s0, s1, e, p;
- e = 1.4e-1;
- b = pi;
- h = pi / 25;
- a = pi / 5;
- i = 1;
- x = a;
- s0 = (pow(-1, i) * cos(i * x)) / (i * i);
- s1 = (pow(-1, (i + 1)) * cos((i + 1) * (x + h))) / ((i + 1) * (i + 1));
- for (x = a; x <= b; x = x + h)
- {
- i++;
- if (fabs(s1 - s0) > e)
- {
- s0 += (pow(-1, i) * cos(i * x)) / (i * i); cout << "s0=" << s0<<"\n";
- s1 += (pow(-1, i) * cos(i * x)) / (i * i); cout << "s1=" << s1<<"\n";
- y = ((x * x) - ((pi * pi) / 3));
- p = fabs(s0 - y);
- cout << "p=" << p << "\n";
- cout << "e=" << e << "\n";
- }
- else
- {
- break;
- }
- }
- cout << "Сумма равна" << s0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment