/*
5 7 18 -1 99
The maximum is: 99
11.11 -33.123 1.321 14.543 87.78
The maximum is: 87.78
*/#include <iostream>usingnamespacestd;
template <typename T>
T max5(const T * a);
template <typename Q>
void show(const Q * a, int n = 5);
int main() {
int arr[5] = {5, 7, 18, -1, 99};
double arr1[5] = {11.11, -33.123, 1.321, 14.543, 87.78};
show(arr);
int n = max5(arr);
cout << "The maximum is: " << n << "\n";
show(arr1);
double n1 = max5(arr1);
cout << "The maximum is: " << n1 << "\n";
return0;
}
template <typename T>
T max5(const T * a) {
int i = 0;
T m = 0;
while (++i < 5) {
if (m < a[i])
m = a[i];
}
return m;
}
template <typename Q>
void show(const Q * a, int n) {
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << "\n";
}