Hi,

I want to know how i can print out the 3 numbers i asked from the user in the ascending numerical order. e.g.

user inputs: 5 1 9

ascending numerical order: 1 5 9

Printable View

- 12-08-2009YiziAscending Numerical Order
Hi,

I want to know how i can print out the 3 numbers i asked from the user in the ascending numerical order. e.g.

user inputs: 5 1 9

ascending numerical order: 1 5 9 - 12-08-2009C_ntua
What have you tried?

- 12-08-2009Epy
Do a search on qsort

- 12-08-2009Epy
- 12-08-2009Yizi
I remember my lecturer doing it in a very easy way with just the stdio.h

- 12-08-2009Adak
If you only have three number to sort, what about using a simpler sort?

Code:`#define SIZE 3`

int i, j, temp;

int a[SIZE] = { 5, 9, 1 };

for(i = 0; i < SIZE - 1; i++) {

for(j = i + 1; j < SIZE; j++) {

if(a[i] > a[j] {

temp = a[i];

a[i] = a[j];

a[j] = temp;

}

}

}

for(i = 0; i < SIZE; i++)

printf("\n %d ", a[i]);

- 12-08-2009Yizi
The problem is the user enters the number so i use scanf to ask for the value.

- 12-08-2009Adak
So put the values into the array

You need to get busy, get out your notes, your book, look over the posts here, and get some work of your own done on this, Yizi.

Programming requires practice, not just asking for help on a forum, and waiting for the code to be done for you.