Answer to Question #13101 in C++ for shalennee

Question #13101
read 5 numbers and print out their in ascending order using do while without using array
1
Expert's answer
2012-08-16T10:34:56-0400
#include <iostream>

#include <stdio.h>




using namespace std;




void swap(int &a, int &b){

int c = a;

a = b;

b = c;

}

int main(){

int a,b,c,d,e;

cout<<"Input 5 numbers
";

cin>>a;

cin>>b;

cin>>c;

cin>>d;

cin>>e;

do{

if(d > e) swap(d,e);

if(c > d) swap(c,d);

if(b > c) swap(b,c);

if(a > b) swap(a,b);

} while (! ((a <= b) && (b <= c) && (c <= d) && (d <= e)) ) ;//while not sorted

cout<<a<<b<<c<<d<<e<<endl;

system("pause");

return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS