-
Notifications
You must be signed in to change notification settings - Fork 0
/
В7.cpp
110 lines (102 loc) · 2.38 KB
/
В7.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <Windows.h>
#include <ctime>
using namespace std;
void randArr(int arr[], const int N, int a, int b);
void printArr(int arr[], const int N);
void zadacha_1(int arr[], const int N);
void zadacha_2(int arr[], const int M);
int main()
{
const int N = 10;
const int M = 20;
int arr[N];
int arr_2[M];
srand(time(NULL));
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
while (true)
{
int num;
cout << "\t\t\t\tMenu:" << endl << endl;
cout << "\t1 - Íà ñê³ëüêè á³ëüøå ñòóäåíò³â íàâ÷àºòüñÿ â íàé÷èñëåíí³ø³é ãðóï³ ïîð³âíÿíî ç íàéìåíøîþ çà ê³ëüê³ñòþ." << endl;
cout << "\t2 - ñê³ëüêè ñòóäåíò³â ìàþòü íàéíèæ÷èé áàë ñåðåä ñòóäåíò³â ãðóïè òà íîìåð ó ñïèñêó ïåðøîãî ç íàéíèæ÷èì áàëîì." << endl;
cout << "\t0 - Âèõ³ä." << endl;
cout << endl << "\tÂâåä³òü ñâ³é âèá³ð: ";
cin >> num;
system("cls");
switch (num)
{
case 1:
randArr(arr, N,20,30);
zadacha_1(arr, N);
system("pause");
break;
case 2:
randArr(arr_2, M, 2, 12);
zadacha_2(arr_2, M);
system("pause");
break;
case 0: exit(0);
default:cout << "Error" << endl;
}
system("cls");
}
}
void printArr(int arr[], const int N)
{
cout << endl << "\n\t|";
for (int i = 0; i < N; i++)
{
cout << arr[i] << " ";
}
cout << "|\n" << endl;
}
void randArr(int arr[], const int N, int a, int b)
{
for (int i = 0; i < N; i++)
{
arr[i] = a + rand() % (b - a + 1);
}
}
void zadacha_1(int arr[], const int N)
{
printArr(arr, N);
int max = arr[0], max_index = 0;
int min = arr[0], min_index = 0;
for (int i = 1; i < N; i++) {
if (arr[i] > max)
{
max = arr[i];
max_index = i;
}
}
for (int i = 1; i < N; i++) {
if (arr[i] < min)
{
min = arr[i];
min_index = i;
}
}
cout <<" íàé÷èñåëüí³ø³é ãðóï³("<<max_index+1<<") íàâ÷àºòüñÿ íà "<<max-min<<" ñòóäåíò³â á³ëüøå â ïîð³âíÿíí³ ç íàéìåíøîþ("<<min_index+1<<")."<< endl;
}
void zadacha_2(int arr[], const int M)
{
printArr(arr, M);
int min = arr[0], min_index = 0, count = 0, first = 0;
for (int i = 1; i < M; i++) {
if (arr[i] < min)
{
min = arr[i];
min_index = i;
}
}
for (int i = M; i > 0; i--) {
if (arr[i] == min)
{
count++;
first = i;
}
}
cout << " ãðóï³ ç " << M << " ÷îëîâ³ê íàéíèæùèé áàë(" << min << ") ìàþòü " << count << " ñòóäåíò³â. Ïåðøèé ç íèõ ó ñïèñêó - " << first + 1 << endl;
}