Please help with displaying 2D array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Please help with displaying 2D array

  1. #1
    Join Date
    Dec 2011
    Posts
    10

    Post Please help with displaying 2D array

    I got assigment at my school to display 2D array like this:

    This is default array:
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16

    Now I have to print the default array like this:

    1 2 6 7
    3 5 8 13
    4 9 12 14
    10 11 15 16

    I have tried some codes to do it myself but i had no succes.

    Please can you give information what algorithm to use, to make this program work:

    Thank you very much!!!
    Attached Images Attached Images  

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: Please help with displaying 2D array

    Well, every zig-zag in the picture is basically the same proceedure, just from a different starting point. That indicates how the outer loop should be defined, eg, the first iteration of the outer loop sets 1-3, the second sets 4-10, the third sets 11-21, etc.

    Within the outer loop, it will probably be easiest to use two separate inner loops, one for traversal in each direction.

    Within each inner loop, it's just a matter of incrementing the indexes appropriately and writing the next number.

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center