# Program to arrange numbers in ascending order and descending order.

• 04-01-2011
jimbo_1
Program to arrange numbers in ascending order and descending order.
Hey guys,
the last 5 hours ive been trying to figure out how to write a single program that can arrange 4 numbers ,that the user will give,in descending,ascending and the order-that-were-given order.

So far i have written 3 different programms for each occasion using the insertion sort algorithm.

However i noticed that im asked to write this program using !only! functions.
I have done a lot of research and i find out nothing except for bubble sort and if-else statements which are very unpractical.

Are there any functions that i can use to write my program,that im not aware of?
I gave up searching,my eyes hurt.
• 04-01-2011
quzah
What do you mean by equations? Do they just want you to compare one item to another and swap them, or are you expecting somehow to swap them with some fancy math?

Quzah.
• 04-01-2011
jimbo_1
Quote:

Originally Posted by quzah
What do you mean by equations? Do they just want you to compare one item to another and swap them, or are you expecting somehow to swap them with some fancy math?

Quzah.

They want us to write a single program that can do all three using only functions,that's all they say!!Im guessing fancy math,but how?
Mind you,that i have only been taught about if-else statements and some basic equations and nothing more.
How hard can it be?

For example lets say that the user has given the numbers 3 4 1 2.
The result in the screen should be the following:
INPUT NUMBER: 3 4 1 2
DESCENDING : 1 2 3 4
ASCENDING: ......

(i edited my post,i meant functions not equations oh well)
• 04-01-2011
quzah
That's still pretty vague. By just using "functions" you could just call the standard qsort function. I am assuming that's not what they expect you to do.

Quzah.
• 04-01-2011
jimbo_1
Quote:

Originally Posted by quzah
That's still pretty vague. By just using "functions" you could just call the standard qsort function. I am assuming that's not what they expect you to do.

Quzah.

And by basic i mean how to calculate absolute value of a number and square root.
Is the qsort easier than the insertion sort?
Can i combine all three into 1 by using the qsort?
• 04-01-2011
quzah
There is a function in C called qsort that will sort for you. Grab your C book, find the index, and look up qsort. Or just read the man page.

Quzah.
• 04-01-2011
CommonTater
Quote:

Originally Posted by jimbo_1
Are there any functions that i can use to write my program,that im not aware of?
I gave up searching,my eyes hurt.

So, are you saying you don't know how to write a function?
• 04-01-2011
jimbo_1
Quote:

Originally Posted by CommonTater
So, are you saying you don't know how to write a function?

im not asking you to give me the right code or do my homework as you initially wrote.
just for some help.
i didnt know if i must use equations like qsort or bubble sort or just make mine.im pretty new to this thing you know and it's just an optional class.
• 04-01-2011
CommonTater
Quote:

Originally Posted by jimbo_1
im not asking you to give me the right code or do my homework as you initially wrote.
just for some help.
i didnt know if i must use equations like qsort or bubble sort or just make mine.im pretty new to this thing you know and it's just an optional class.

Yeah that's why I re-edited as an afterthought... I do that sometimes.

I'd say the assignment wants you to write your own functions to sort the lists.
It's a pretty routine part of any C language programming task.
• 04-01-2011
```void sort(int numbers[SIZE], int typeOfSort) { //might be the first line of your sort function.   //declare your variables here   if(typeOfSort == 0) {     //put an ascending sort in here   }   else {     //put a descending sort in here   } }```