Numbers in descending order(HELP)!

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2008
Posts: 23
Reputation: Demonisya is an unknown quantity at this point 
Solved Threads: 0
Demonisya's Avatar
Demonisya Demonisya is offline Offline
Newbie Poster

Numbers in descending order(HELP)!

 
0
  #1
Jan 28th, 2009
Hello Once Again..... I need you to help me with this program im working. My teacher asked me to create a program that could arrange the random numbers from lowest to highest.... but I can't follow up what's next in my program:

  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4. {
  5. int a,b[10];
  6. for(a=1,a<=10,a++)
  7. {
  8. printf("Enter Number %d",a);
  9. scanf("%d",&b[a]);
  10. }
  11. for(b=0,b<=a,b--)
  12. {
  13. printf("The Numbers in Descending order:%d\n",b[a])
  14. }
  15. return 0;

Is The 2nd loop correct????
I'm a Beginner and I want to learn HARD.....So Don't Judge me I'm Not a BOOK....O.K???? Thanks....
LOVE YOU ALL!!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Numbers in descending order(HELP)!

 
0
  #2
Jan 28th, 2009
your desciption indicates that you will be given a list of random numbers that will be in no particualr order. thus you cannot just loop through the array backwards. You will need to perform some form of sorting algorithm such as a Bubble Sort

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 76
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training

Re: Numbers in descending order(HELP)!

 
0
  #3
Jan 28th, 2009
Firstly...
  1. for(b=0,b<=a,b--)
  2. {
  3. printf("The Numbers in Descending order:%d\n",b[a]);
  4. }
is wrong.As you can see you are starting b's count from 0 and doing a b-- operation.

Secondly...
You need some sorting mechanism to sort your arrray.The simplest to understand may be selection sort to start with.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: Demonisya is an unknown quantity at this point 
Solved Threads: 0
Demonisya's Avatar
Demonisya Demonisya is offline Offline
Newbie Poster

Re: Numbers in descending order(HELP)!

 
0
  #4
Jan 29th, 2009
What do i have to use in order to obtain the acsending order????
I'm a Beginner and I want to learn HARD.....So Don't Judge me I'm Not a BOOK....O.K???? Thanks....
LOVE YOU ALL!!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: Numbers in descending order(HELP)!

 
0
  #5
Jan 29th, 2009
A bubble sort but with the comparison flipped.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 17
Reputation: its.romi is an unknown quantity at this point 
Solved Threads: 1
its.romi its.romi is offline Offline
Newbie Poster

Re: Numbers in descending order(HELP)!

 
0
  #6
Jan 30th, 2009
Well, a simple logic for u is that
1. maintain loop which will run until a condition occurs ( that condition i will tell u a bit later)
2. now in that while loop read the first two number, if the 2nd one is greater than one than swap both number and place in the array again, do the same for 2nd and 3rd elements, and continue doing it until the end of the array.
3. The array will not be sorted on first iteration, we have to continue swapping the elements of array till it will have been sorted in descending order
4. Now lets talk about the condition of while loop, take a variable, and the value of this variable resets to 0 with the start of while loop, and the value of that variable, say x, gets incremented when there is a swapping occur in the whole list. So your while loop will stop if the value of variable x is 0 at the end of any iteration.

This is a slow and time taking algorithm, but its easy to understand. I will provide u the code if u need
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: Demonisya is an unknown quantity at this point 
Solved Threads: 0
Demonisya's Avatar
Demonisya Demonisya is offline Offline
Newbie Poster

Re: Numbers in descending order(HELP)!

 
0
  #7
Jan 30th, 2009
Yeah...it really takes a long time to finish it.... I barely got the half of it.... anyways I got a fair grade of trying.... but sir still didn't gave us the answer... but I will try your advice on swapping the arrays.... but before I ask for your code I'll have to try my best on this one...... you can give me your code and I'll try to study It on my own..... I really appreciate your help.... ^^
I'm a Beginner and I want to learn HARD.....So Don't Judge me I'm Not a BOOK....O.K???? Thanks....
LOVE YOU ALL!!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 17
Reputation: its.romi is an unknown quantity at this point 
Solved Threads: 1
its.romi its.romi is offline Offline
Newbie Poster

Re: Numbers in descending order(HELP)!

 
-1
  #8
Jan 30th, 2009
Solution has been sent to you ... however i didnt compile the code, but it will work, i just forgot to set the boundries of array and hope that u will do it by using a nested while loop of if condition, when u try yourself.

Have a happy programming
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Numbers in descending order(HELP)!

 
1
  #9
Jan 30th, 2009
Originally Posted by its.romi View Post
Solution has been sent to you ... however i didnt compile the code, but it will work, i just forgot to set the boundries of array and hope that u will do it by using a nested while loop of if condition, when u try yourself.

Have a happy programming
Please don't PM code solutions. I suggest re-reading the forums rules too. Just to make sure you understand how we work when it comes to handing out code.

Secondly, code solutions are best in the thread they are the solution for. So in the future people are able to search for solutions to problems and find it. Rather than having to start a new topic, waste more peoples time purely because some goon wouldn't share a solution.

Chris
Last edited by Freaky_Chris; Jan 30th, 2009 at 6:20 am.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: Demonisya is an unknown quantity at this point 
Solved Threads: 0
Demonisya's Avatar
Demonisya Demonisya is offline Offline
Newbie Poster

Re: Numbers in descending order(HELP)!

 
0
  #10
Jan 31st, 2009
I have read the bubble sort but may I ask you what does beside of n ( := ) do?? I got this example in wikipedia....

  1.  
  2. n := length( A )
  3. do
  4. swapped := false
  5. n := n - 1
  6. for each i in 0 to n - 1 inclusive do:
  7. if A[ i ] > A[ i + 1 ] then
  8. swap( A[ i ], A[ i + 1 ] )
  9. swapped := true
  10. end if
  11. end for
  12. while swapped
  13. end procedure
I'm a Beginner and I want to learn HARD.....So Don't Judge me I'm Not a BOOK....O.K???? Thanks....
LOVE YOU ALL!!!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC