#include <iostream>
using namespace std;
const int SIZE = 5;
template <class T>
T max5(const T a[]) {
int i = 0;
T temp = a[i];
for (i++; i < SIZE; i++) {
if (temp < a[i])
temp = a[i];
}
return temp;
}
template <class T>
void show(const T a[]) {
cout << "All of the array element number: ";
for (int i = 0; i < SIZE; i++)
cout << a[i] << ' ';
cout << "\n";
return;
}
int main() {
int a[SIZE] = {3, 5, -1, 10 ,22};
float b[SIZE] = {4.4, -8, 88.789, -22.123, 1};
int biggest = max5(a);
float biggest1 = max5(b);
show(a);
cout << "The biggest number is: " << biggest << "\n";
show(b);
cout << "The biggest number is: " << biggest1 << "\n";
return 0;
}
/*
All of the array element number: 3 5 -1 10 22
The biggest number is: 22
All of the array element number: 4.4 -8 88.789 -22.123 1
The biggest number is: 88.789
*/
c++ primer plus 第八章《编程题8.8.5》
最新推荐文章于 2022-04-28 12:01:27 发布