Thread: Trying to sort numbers from lowest to highest

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Well, you could sort them, that's an easy way to know which is the lowest, highest and which is in middle

    Code:
    if (i2 > i3)
        // swap i2 and i3
    if (i1 > i2)
        // swap i1 and i2
    if (i2 > i3)
        // swap i2 and i3
    /* A: i1 is lowest number, i2 is middle, i3 is highest */

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    14
    I am not sure about your question. did you try the conditional operator?
    something like:

    if (i1<i2)
    {
    low =(i1<i3 ? i1 : i3);
    med = (i2<i3 ? i2 : i3);
    high =(i2<i3 ? i3 : i2);
    }
    if (i2<i1)
    {
    low =(i2<i3 ? i2 : i3);
    med = (i1<i3 ? i1 : i3);
    high =(i1<i3 ? i3 : i1);
    }

    but the problem is it is multiple statements.
    Last edited by jojo13; 01-19-2008 at 01:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting lowest and highest score from array
    By sjalesho in forum C Programming
    Replies: 6
    Last Post: 03-01-2011, 06:24 PM
  2. Displaying highest and lowest values
    By beastofhonor in forum C++ Programming
    Replies: 3
    Last Post: 10-29-2006, 08:24 PM
  3. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  4. Help On A Quick Sort Program
    By nick4 in forum C++ Programming
    Replies: 11
    Last Post: 12-06-2004, 10:51 AM
  5. interpolation sort
    By saigonara in forum C Programming
    Replies: 5
    Last Post: 07-14-2002, 06:58 PM