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 < rows; row++)
{
for (int column = 0; column < columns ; column++)
{
twodim[row][column] = onedim[maxrowIndex*columns+column];
}
maxrowIndex--;
}
Here is the second code
int maxrowIndex = rows-1;
for (int row = 0; row < rows-1; row++)
{
for (int column = 0; column < 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 ?
the first row and the last column of the original 1-dimensional array
how does a 1-dimensional array have rows and columns? I don't quite understand the question, could you provide an example? \$\endgroup\$ – cbreezier May 24 '15 at 7:53