从终端输入10个整数,输出其中最大的数和次打的数。要求输入的10个整数互不相等。
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int a, maxval = -1000, secondval = -1000, i;
for (i = 1; i <= 10; i++)
{
cin >> a;
if (a > maxval)
{
secondval = maxval;
maxval = a;
}
else
{
if (a > secondval)
{
secondval = a;
}
}
}
cout << "the max is:" << maxval << endl;
cout << "the second is:" << secondval << endl;
return 0;
}