Thread: display in ascending order multidimensional integer values

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    24

    display in ascending order multidimensional integer values

    I have a code as shown below, which produces output as below

    83,72,91,42,0,78,92,81,68,0,82,55,36,22,11,

    but actually I want output in ascending order like
    0,0,11,22,36,42,55,68,72,78,81,82,83,91,92

    How it can be done?



    Code:
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int main ()
    {
        int array[3][5]= {{83,72,91,42},{78,92,81,68},{82,55,36,22,11}},i,j;
        for (i=0; i<3; i++)
        {
            for (j=0; j<5; j++)
            {
                cout <<   array[i][j];
                cout << ",";
            }
    
        }
    cin.get ();
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Looks like you'll need to sort the array.

    Jim

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    24
    HI Jim,

    How can I do the sorting? Can you please post a sample code?

    FYI: I'm just a beginner for programming

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I suggest you use your favorite search engine to search for information on sorting arrays. Something like "C++ sorting arrays" would probably get you thousands of pages to view. Learning to research the problem is one of the biggest skills you will need to learn to become an actual programmer.

    Jim

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    24
    i already searched online before creating a new thread here. Most of the pages were just complicated for me to understand.

    Thanks. I will keep trying, hope I will get something easier.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Well since you haven't shown anything related to sorting, or even asked about how to sort, how would anyone, other than yourself, know that?

    Show what you've tried, and ask specific questions about what you don't understand. Sorting in C++ can be very simple, if you are allowed to use some standard C++ functions like std::sort.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 04-01-2011, 04:13 PM
  2. ascending and descending order
    By ssk in forum C Programming
    Replies: 3
    Last Post: 03-25-2011, 08:03 PM
  3. Ascending Numerical Order
    By Yizi in forum C Programming
    Replies: 7
    Last Post: 12-08-2009, 07:05 PM
  4. 3 integers in ascending order
    By hobilla in forum C Programming
    Replies: 7
    Last Post: 02-14-2009, 01:01 PM
  5. organize values of array in ascending order
    By incognito in forum C++ Programming
    Replies: 4
    Last Post: 11-08-2003, 10:55 PM