Wednesday, February 15, 2012

1D Array into 2D table.


You are given a 1D array of integers, such as:
int[] array = [3,4,7,2,2,6,0,9];
Suppose you need to treat this array as a 2D table with a given number of rows.
You want to sum the columns of the table.
One value of numRows is 4..in that case the resultant array would look like
3 4
7 2
2 6
0 9
—-
12 21

No comments:

Post a Comment