include iostream template std size_t double getMaximum double array do

 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
#include <iostream>
template<std::size_t S>
double getMaximum(double (&array)[S]) {
double max = 0;
for(const auto &element: array)
if (abs(element) > max) max = abs(element);
return max;
}
template<std::size_t S>
double getMaximum(double (&array)[S][S]) {
double max = 0;
for(const auto &elements: array)
for(const auto &element: elements)
if (abs(element) > max) max = abs(element);
return max;
}
int main() {
double array[10], array2[4][4];
std::cout << "input array[10]" << std::endl;
for(auto &element: array)
std::cin >> element;
std::cout << "input array2[4][4]" << std::endl;
for(auto &elements: array2)
for(auto &element: elements)
std::cin >> element;
std::cout
<< "biggest value in array[10] => " << getMaximum(array) << std::endl
<< "biggest value in array[4][4] => " << getMaximum(array2) << std::endl;
return 0;
}