Copying one dimensional array bottom to top I want to convert a one dimensional array to a two dimensional array with the following conditions and have followed the code from this question - https://stackoverflow.com/questions/1817631/iterating-one-dimension-array-as-two-dimension-array. The 2-dimensional array has to be copied from the one dimensional array and written bottom to top. The second condition is that while the 1-dim array is being copied bottom to top the first row and the last column of the original 1-dimensional array must not appear in the two dimensional array if one were to visualize the 1-dim as a 2-dim array. 

int maxrowIndex = rows-1;
for (int row = 0; row &lt; rows; row++)
    {
        for (int column = 0; column &lt; columns ; column++)
            {
               twodim[row][column] = onedim[maxrowIndex*columns+column];

            }
        maxrowIndex--;
    }


Here is the second code 

int maxrowIndex = rows-1;
for (int row = 0; row &lt; rows-1; row++)
    {
        for (int column = 0; column &lt; columns-1 ; column++)
            {
               twodim[row][column] = onedim[maxrowIndex*columns+column];

            }
        maxrowIndex--;
    }


Did I get it right ? Is there any way I can improve the code ?
OK, so from what I can understand about your problem is that you want to "chunk" up a one-dimensional array into a two-dimensional array with rows rows and columns columns.

I'm going to assume row-major form since that's a little bit more typical (and seems to be what your code does too).

First of all, I don't understand the condition where it has to be written from bottom to up. I don't see any reason for this, but we'll assume we do have to do that for whatever reason.

Your code does not quite work, because you've confused the row variable and the maxrowIndex variable. In the part where you are attempting to calculate the one-dimensional index based on a given row and column you use this maxrowIndex variable which hints at it actually storing the current row index. But you do not use this when indexing your two-dimensional array.

In terms of style, I have to say that I'm not a fan of opening the brace { on the next line, and especially not indenting twice each time you nest.

Here's how I would approach the problem:

Edit: clarification - the data was original written north to south ([0][0] would have been the north west corner) and we need to flip vertically so that the new [0][0] should be the south west corner.

// We ignore the first row of the original array (which is the last row of the new 2d array
for (int row = 0; row &lt; rows - 1; row++) {
    // From first column to second last column (skips last column)
    for (int column = 0; column &lt; columns; columns++) {
        int originalRow = rows - 1 - row;
        twodim[row][column] = onedim[originalRow*columns + column];
    }
}