-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAB(3)(+)_Sum.cpp
More file actions
59 lines (57 loc) · 1.92 KB
/
Copy pathLAB(3)(+)_Sum.cpp
File metadata and controls
59 lines (57 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int x = 1;
double n = (log(x) + sin(x)) / (x * x + log(x));
double s = n;
x++;
cout << "Цикл FOR" << endl << endl;
for (; n >= 0.0002; x++)
{
n = (log(x) + sin(x)) / (x * x + log(x));
s += n;
if (x == 20) cout << "Сумма первых 20 элементов: " << s << endl;
if (x == 50) cout << "Сумма первых 50 элементов: " << s << endl;
if (x == 90) cout << "Сумма первых 90 элементов: " << s << endl;
}
cout << endl;
cout << "Сумма с заданной точностью: " << s << " При кол-ве элементов:" << x-1 << endl;
cin.get();
x = 1;
n = (log(x) + sin(x)) / (x * x + log(x));
s = n;
x++;
cout << "Цикл WHILE" << endl << endl;
while (n >= 0.0002 )
{
n = (log(x) + sin(x)) / (x * x + log(x));
s += n;
if (x == 20) cout << "Сумма первых 20 элементов: " << s << endl;
if (x == 50) cout << "Сумма первых 50 элементов: " << s << endl;
if (x == 90) cout << "Сумма первых 90 элементов: " << s << endl;
x++;
}
cout << endl;
cout << "Сумма с заданной точностью: " << s << " При кол-ве элементов:" << x-1 << endl;
cin.get();
x = 1;
s = (log(x) + sin(x)) / (x * x + log(x));
x++;
cout << "Цикл DO WHILE" << endl << endl;
do
{
n = (log(x) + sin(x)) / (x * x + log(x));
s += n;
if (x == 20) cout << "Сумма первых 20 элементов: " << s << endl;
if (x == 50) cout << "Сумма первых 50 элементов: " << s << endl;
if (x == 90) cout << "Сумма первых 90 элементов: " << s << endl;
x++;
} while (n >= 0.0002);
cout << endl;
cout << "Сумма с заданной точностью: " << s << " При кол-ве элементов:" << x-1 << endl;
cin.get();
return 0;
}