-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlab2_1.cpp
72 lines (59 loc) · 1.33 KB
/
lab2_1.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>
int main()
{
// if
{
const int right = 25;
// right = 234; // error
int answer = 0;
std::cout << "5 * 5 = ?" << std::endl;
std::cin >> answer;
if (answer == right)
{
std::cout << "All right!" << std::endl;
}
else
{
std::cout << "You're looser" << std::endl;
}
}
// for
{
unsigned int n = 0;
std::cout << "Enter a number:" << std::endl;
std::cin >> n;
unsigned int fact = 1;
for (unsigned int i = 2; i <= n; ++i)
{
fact = fact * i;
}
std::cout << n << "! = " << fact << std::endl;
}
// while
{
unsigned int n = 0;
std::cout << "Enter a number:" << std::endl;
std::cin >> n;
std::cout << "Summ(0..." << n << ") = ";
unsigned int summ = 0;
while (n != 0)
{
summ += n;
n--;
}
std::cout << summ << std::endl;
}
// do while
{
const int right = 25;
int answer = 0;
do
{
std::cout << "5 * 5 = ?" << std::endl;
std::cin >> answer;
} while (answer != right);
std::cout << "All right!" << std::endl;
}
return 0;
}