Results 1 to 4 of 4

Thread: Display numbers

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Display numbers

    How to make a program that to display the numbers from biggest to small number

    I write 3 numbers for example: 2, 6, 1
    This are the numbers that i will write
    and to display them in this type from biggest to smallest : 6, 2, 1
    How to do it?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Display numbers

    You would preferably store the values in an array and sort it using the sorting algorithm of your choice. There are lots of sorting algorithms to choose from. Most beginners would implement bubble sorting, which is a terribly inefficient algorithm but for small sets of data in an application that is not performance-critical it is sufficient.
    If you are interested in performance, look into quicksort.

    I believe the standard template library includes an implementation of quicksort, but I take it you are looking to implement the algorithm yourself?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Display numbers

    can you show how should be done, cause i dont get it

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Display numbers

    What is it that you don't get?
    Have you looked at the std::sort function? Include the algorithm header and you'll find it.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width