Results 1 to 2 of 2

Thread: Print array by column help.

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    38

    Exclamation Print array by column help.

    I have two arrays:

    Code:
    int array1[][] = { { 1, 2, 3 }, 
                       { 4, 5, 6 } };
                             
    int array2[][] = { { 1, 2 }, 
                       { 3 }, 
                       { 4, 5, 6 } };
    I need to print both of them by column like this:

    Code:
    14
    25
    36
    
    and
    
    
    134
    2 5
      6
    I can do the first one, but I don't know how do do the second one using array.length and array[ row ].length. How do I do this? Thanks

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    First you need to find the longest of the subarrays. That's your base length and loop count.

    Then on each iteration you simply check if the current subarray still has elements.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width