I need an ascending output. needs to be based only on if and else if statements. Is there anything I have missed or any shorter way to write the code?? please advise
#include <iostream>
using namespace std;
int main () {
int A, B, C;
cin>>A>>B>>C;
if ((A<=B)&&(B<=C)&&(A<=C)) {
cout<<A<<" "<<B<<" "<<C;
}else if((A<=B)&&(C<=B)&&(A<=B)) {
cout<<A<<" "<<C<<" "<<B;
}else if ((B<=A)&&(A<=C)&&(B<=C)) {
cout<<B<<" "<<A<<" "<<C;
}else if ((B<=C)&&(C<=A)&&(B<=A)) {
cout<<B<<" "<<C<<" "<<A;
}else if ((C<=A)&&(A<=B)&&(C<=B)) {
cout<<C<<" "<<A<<" "<<B;
}else if ((C<=B)&&(B<=A)&&(C<=A)) {
cout<<C<<" "<<B<<" "<<A;
}else if ((A==B)&&(B==C)&&(A==C)) {
cout<<A<<" "<<B<<" "<<C;
}
return 0;
}
expected ascending output
Aucun commentaire:
Enregistrer un commentaire