making comparison between two or more than two numbers

This is a discussion on making comparison between two or more than two numbers within the C++ Programming forums, part of the General Programming Boards category; Hi I'm writing an algorithm where I need to make comparison between four numbers X, Y, Z, and W to ...

  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
    5,883
    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%.

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,529
    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, 10: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, 09:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21