Thread: making comparison between two or more than two numbers

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    making comparison between two or more than two numbers

    Hi

    I'm writing an algorithm where I need to make comparison between four numbers X, Y, Z, and W to arrange them in a descending order.

    Get the numbers X, Y, Z, and W
    Make Comparison between X, Y, Z, and W
    Show the largest of four
    Compare the remaining three numbers
    .
    .
    .
    Stop

    I have a feeling this is not a correct algorithm. What is your opinion? Could you please help me? First I need to write an algorithm, implementation would be next step. Thanks.
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Google for "sorting algorithm". Normally these things work better on arrays than on distinct variables - simply copy the value of X to data[0], Y to data[1], etc and sort the array named data.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Or read your other thread that you made today. Sorting was probably mentioned in the first post.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to reverse numbers with sizeof operator
    By JoelearningC in forum C Programming
    Replies: 13
    Last Post: 03-09-2008, 11:53 AM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM