include iostream using namespace std template typename test matrix siz

 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
#include <iostream>
using namespace std;
template <typename T> T test(T** matrix, size_t n, size_t m) {
T *array = new T[n * m];
for (size_t i = 0; i < n; ++i) {
T max = matrix[i][0];
for (size_t j = 0; j < m; ++j) {
if (matrix[i][j] > max)
max = matrix[i][j];
array[i * m + j] = matrix[i][j];
}
cout << "Линия #" << i << ", Максимальное значение: " << max << "\n";
}
cout << "Одномерный массив:\n";
T min = array[0];
for (size_t i = 0; i < n * m; ++i) {
if (array[i] < min)
min = array[i];
cout << array[i] << " ";
}
cout << "\n";
cout << "Минимальный среди всех: " << min << "\n";
return 0;
}
int main() {
size_t n, m;
cout << "[INT]\n";
cout << "Кол-во строк:\n";
cin >> n;
cout << "Ширина строк:\n";
cin >> m;
int **matrix = new int*[n];
for (size_t i = 0; i < n; ++i) {
matrix[i] = new int[m];
cout << "Строка #" << i << "\n";
for (size_t j = 0; j < m; ++j)
cin >> matrix[i][j];
}
test<int>(matrix, n, m);
for (size_t i = 0; i < n; ++i)
delete[] matrix[i];
delete[] matrix;
cout << "[АДЩФЕ]\n";
cout << "Кол-во строк:\n";
cin >> n;
cout << "Ширина строк:\n";
cin >> m;
float **matrix2 = new float*[n];
for (size_t i = 0; i < n; ++i) {
matrix2[i] = new float[m];
cout << "Строка #" << i << "\n";
for (size_t j = 0; j < m; ++j)
cin >> matrix2[i][j];
}
test<float>(matrix2, n, m);
for (size_t i = 0; i < n; ++i)
delete[] matrix2[i];
delete[] matrix2;
cin.get();
return 0;
}