#include <iostream>
using namespace std;
int Max_2(int a[] , int len)
{
int max = a[0];
int max_2 = a[0];
for (int i = 0; i < len; i++) {
if (max < a[i]) {
max = a[i];
}
}
for (int i = 0; i < len; i++) {
if (max_2 < a[i] && a[i] < max) {
max_2 = a[i];
}
}
return max_2;
}
結果實例:
請輸入需要判斷的數的個數:5
請輸入這5個數
7 8 5 2 9
第二個最大的數爲:8
如有不對,歡迎指出,大家共同學習