-
Notifications
You must be signed in to change notification settings - Fork 0
/
peta_zadacha.cpp
94 lines (83 loc) · 1.75 KB
/
peta_zadacha.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
#include <iostream>
using namespace std;
void printValue (int val)
{
if (val <= 9)
{
cout << val << " |";
}
if (val > 9 && val <= 99)
{
cout << val << " |";
}
if (val > 99)
{
cout << val << "|";
}
}
int read_input(int min, int max, string message)
{
int input = -1;
bool valid= false;
do
{
cout << message << flush;
cin >> input;
if (cin.good() && input >= min && input <= max)
{
valid = true;
}
else
{
cin.clear();
cout << "Invalid input; please re-enter." << endl;
}
} while (!valid);
return (input);
}
int main()
{
int cols, rows, matrix[10][10];
cols = read_input(1, 50, "Enter cols (range 1-50): ");
rows = read_input(1, 50, "Enter rows (range 1-50): ");
cout << "Enter the elements matrix (range 1-999): " << endl;
int min = 100000;
int max = 0;
int minRow = 0;
int maxCol = 0;
for(int x = 0; x < rows; x++)
{
for(int y = 0; y < cols; y++)
{
cin >> matrix[x][y];
if(matrix[x][y] > max)
{
max = matrix[x][y];
maxCol = y;
}
if(matrix[x][y] < min)
{
min = matrix[x][y];
minRow = x;
}
}
}
for(int x = 0; x < rows; x++)
{
cout << "|";
for(int y = 0; y < cols; y++)
{
if (x == minRow)
{
matrix[x][y] = 100;
}
if (y == maxCol)
{
matrix[x][y] = 10;
}
printValue (matrix[x][y]);
}
cout << endl;
}
return 0;
}