|
改进第二题 求次大值- #include<iostream>
- using namespace std;
- int x1,x2,i,max1,max2;
- int main()
- {
- cin>>x1>>x2;
- if (x1>x2){max1=x1;max2=x2;}
- else {max1=x2;max2=x1;}
- for (i=3;i<=10;i++)
- {
- cin>>x1;
- if (x1>max1) {max2=max1;max1=x1;}
- else if (x1>max2) {max2=x1;}
- }
- cout<<max2;
- return 0;
- }
复制代码 |
|