60 507
Assignments Done
98,1%
Successfully Done
In April 2018

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
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions