Thursday, July 30, 2009

Code in C programming that after i enter 10 numbers i can sort them from lowest to highest or vice versa.?

What is the code in C programming that after i enter 10 numbers i can sort them from ascending to descending or descending to ascending? Please i really need your responce. Thank you.

Code in C programming that after i enter 10 numbers i can sort them from lowest to highest or vice versa.?
10!
Reply:You should at least TRY to figure it out yourself. Then post the code if you get stuck. Show us that you did *something* yourself. I'm happy to help people, but I'm not going to do it for you. There are too many people like you in this industry already, and you are hurting everyone else. Learn to do things on your own or go work at McDonald's where they tell you everything you're supposed to do.





This is a no-brainer insertion sort.
Reply:Since you have a small number of numbers to sort, I'd just use a classic bubble sort. I'll give you the algorithm and you can code it up.





for ( i=0 ; i%26lt;10 ; i++) {


for ( j=0 ; j%26lt;10 ; j++) {


if(A[ j ] %26lt; A[ j - 1 ]) {


swap( A[ j ], A[ j - 1 ] );


}


}


}





You will need to create your swap method.


and if you need them in reverse order, just print them out backwards.





There are many ways of sorting stuff. This is a quick and dirty approach and is only recommended for a VERY small number of elements. Do youself a favor and do a hand trace on a couple of tests and make sure you understand what is going on or I have done you no favor. This algorithm is easy to find from books and on the web as well as countless others. Sorting is an exciting area of study. Explore it.





Have fun.
Reply:Are you some sort of bot who asks simple C questions?? ;)

house plants

No comments:

Post a Comment