Ascending Numerical Order

This is a discussion on Ascending Numerical Order within the C Programming forums, part of the General Programming Boards category; Hi, I want to know how i can print out the 3 numbers i asked from the user in the ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    6

    Ascending Numerical Order

    Hi,

    I want to know how i can print out the 3 numbers i asked from the user in the ascending numerical order. e.g.

    user inputs: 5 1 9
    ascending numerical order: 1 5 9

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    What have you tried?

  3. #3
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    994
    Do a search on qsort

  4. #4
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    994

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    6
    I remember my lecturer doing it in a very easy way with just the stdio.h

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you only have three number to sort, what about using a simpler sort?

    Code:
    #define SIZE 3
    
    int i, j, temp;
    int a[SIZE] = { 5, 9, 1 };
    
    for(i = 0; i < SIZE - 1; i++) {
      for(j = i + 1; j < SIZE; j++) {
        if(a[i] > a[j] {
          temp = a[i];
          a[i] = a[j];
          a[j] = temp;
        }
      }
    }
    
    for(i = 0; i < SIZE; i++)
      printf("\n %d ", a[i]);

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    6
    The problem is the user enters the number so i use scanf to ask for the value.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    So put the values into the array

    You need to get busy, get out your notes, your book, look over the posts here, and get some work of your own done on this, Yizi.

    Programming requires practice, not just asking for help on a forum, and waiting for the code to be done for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3 integers in ascending order
    By hobilla in forum C Programming
    Replies: 7
    Last Post: 02-14-2009, 01:01 PM
  2. Program to print 3 numbers in ascending order
    By jadedreality in forum C++ Programming
    Replies: 5
    Last Post: 11-08-2007, 07:32 PM
  3. Problem with ascending order Program
    By cashmerelc in forum C Programming
    Replies: 4
    Last Post: 09-21-2007, 06:36 PM
  4. Arranging numbers in ascending order
    By Aero in forum C++ Programming
    Replies: 7
    Last Post: 12-22-2001, 07:52 AM
  5. arranging randomly generated numbers in ascending order
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-05-2001, 07:14 PM

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