# 3 integers in ascending order-help

• 10-31-2001
Allison23NY
3 integers in ascending order-help
For the life of me I can not figure out how to efficiently code placing three integers in ascending order! I can do it with a bazillion lines of code but I'm certain there is a shorter way.

int num1;
int num2;
int num3;

int min;
int mid;
int max;

(I'm too embarrassed to write those bazillion lines of code!)

any help would be greatly appreciated.

Alli
• 10-31-2001
no-one
what do you mean?

something like this will work

int num1,num2,num3;

or

int min,mid,max;
• 10-31-2001
Allison23NY
whoops! I meant to say that the 3 integers are read in from a file ... then need to be sorted into ascending order then displayed on the screen. I just don't know how to write the tests using say five lines of code.
• 10-31-2001
Salem
Well this is the algorithm - all you need to do is arrange the input, and figure out how to swap two variables

Code:

```    if ( a > b ) swap(a,b);     if ( b > c ) swap(b,c);  // c is now the largest     if ( a > b ) swap(a,b);  // a and b are also in order```