2D array fill

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silversnake
    New Member
    • Mar 2007
    • 11

    2D array fill

    hi all I need to write a function that fill the array with the numbers 1 to 54 in ascending order going from left to right then top to bottom. Therefore 1 will be in the top left hand corner, 6 in the top right hand corner, 49 in the bottom left corner
    and 54 in the bottom right hand corner. I know how to fill left to right with one for loop but how do I do it with a 2D array??

    thanks again
  • arne
    Recognized Expert Contributor
    • Oct 2006
    • 315

    #2
    Originally posted by silversnake
    hi all I need to write a function that fill the array with the numbers 1 to 54 in ascending order going from left to right then top to bottom. Therefore 1 will be in the top left hand corner, 6 in the top right hand corner, 49 in the bottom left corner
    and 54 in the bottom right hand corner. I know how to fill left to right with one for loop but how do I do it with a 2D array??

    thanks again
    See if this works
    Code:
            int i, array[9][6];
            for (i=1; i<55; i++) {
                    *(*array + i - 1) = i;
            }

    Comment

    Working...