【Problem Description】
Input 4 integers from the keyboard and output them in descending order.
[Input form]
Enter 4 integers per line
[output format]
In one line, output the 4 integers after sorting
[sample input]
15 234 5 18
【Sample output】
234 18 15 5
Analysis of thinking: introduce a variable, realize the exchange of big numbers and small numbers through assignment, so as to realize the sorting
code as follows:
#include
using namespace std;
int main() {
int a,b,c,d,e;
cin>>a>>b>>c>>d;
if(a<b){
e=a;
a=b;
b=e;
}
if(a<c){
e=a;
a=c;
c=e;
}
if(a<d){
e=a;
a=d;
d=e;
}
if(b<c){
e=b;
b=c;
c=e;
}
if(b<d){
e=b;
b=d;
d=e;
}
if(c<d){
e=c;
c=d;
d=e;
}
cout<<a<<" "<<b<<" "<<c<<" "<<d;
}