Сделать блок схемы к даным алгоритмам:
1.
#include
#include
using namespace std;
int nod(int a, int b) {
if (a == 0)
return b;
if (b == 0)
return b;
while (a != b) {
if (a > b) {
a = a - b;
}
else {
b = b - a;
}
}
return a;
}
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int num1, num2;
cout << "Введіть два числа: " << endl;
cin >> num1 >> num2;
cout << "НОД " << num1 << " і " << num2 << " = ";
cout << nod(num1, num2);
return 0;
}
2.
#include
#include
using namespace std;
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int n;
cout << "Введіть числo: " << endl;
cin >> n;
int result = n;
cout << "Кількість чисел взаємопростих у відрізку [1 ," << n << " ] ";
for (int i = 2; i * i <= n; ++i)
if (n % i == 0) {
while (n % i == 0)
n /= i;
result -= result / i;
}
if (n > 1) {
result -= result / n;
}
cout << result;
return 0;
};
Ответы
Ответ:
Блок схемы к данным алгоритмам могут выглядеть так:
1)
+---------+
| num1 |
+---------+
|
|
+-------------+------------+
| |
| num2 |
| |
+-------------------------+
|
|
+-------------+------------+
| |
| (num1 == 0) |
| |
+-------------------------+
|
|
v
+------------+
| |
| return b |
| |
+------------+
|
|
+-------------+------------+
| |
| (b == 0) |
| |
+-------------------------+
|
|
v
+------------+
| |
| return a |
| |
+------------+
|
|
v
+------------+
| |
| (a != b) |
| |
+------------+
|
|
+-------------+------------+
| |
| |
| |
+-------------------------+
|
|
v
+------------+
| |
| (a > b) |
| |
+------------+
|
|
+-------------+------------+
| |
| |
| |
+-------------------------+
|
|
v
+------------+
| |
| a = a - b |
| |
+------------+
|
|
v
+------------+
| |
| (a != b) |
| |
+------------+
|
|
+-------------+------------+
| |
| |
| |
+-------------------------+
|
|
v
+------------+
| |
| b = b - a |
| |
+------------+
|
|
v
+------------+
| |
| (a != b) |
| |
+------------+
.
.
.
2) +---------+
| n |
+---------+
|
|
+-------------+------------+
| |
| |
| |
+-------------------------+
|
|
v
+------------+
| |
| result = n|
| |
+------------+
|
|
+-------------+------------+
| |
| |
| |
+-------------------------+
|
|
+-------------+------------+
| |
| (i * i <= n) |
| |
+-------------------------+
|
|
v
+------------+
| |
| (n % i == 0)|
| |
+------------+
|
|
+-------------+------------+
| |
| |
| |
+-------------------------+
|
|
v
+------------+
| |
| n /= i |
| |
+------------+
|
|
+-------------+------------+
| |
| (n % i == 0) |
| |
+-------------------------+
|
|
v
+------------+
| |
| result -= |
| result / I |
| |
+------------+
|
|
+-------------+------------+
| |
| (i * i <= n) |
| |
+-------------------------+
|
|
v
+-------------+------------+
| |
| (n > 1) |
| |
+-------------------------+
|
|
v
+------------+
| |
| result -= |
| result / n |
| |
+------------+