用while找出最大值及次最大值
做了很久也在紙上拿起筆寫過又想過
只能找到最大值 次最大值怎麼找?
如輸入10,5,6,3,7,8,9,4,6,2
最大是10 次大值是9
想了久久久 只能做出最大而已=.=\"
#include \"stdafx.h\"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int x;
int counter = 1;
int max = 1;
while ( counter <= 10 ){
cout << \"輸入數字: \";
cin >> x;
if ( x >= max )
max = x;
counter += 1;
}
cout << \"最最大值 = \" << max << endl;
return 0;
}
還有問題?馬上發問,尋求解答。