With a 1D array that uses the same amount of memory as a 2D array, a2Darray[i][j] is equal to a1Darray[i * maxi + j], where a2Darray is declared as a2Darray[maxi][maxj] and a1Darray is declared as a1Darray[maxi * maxj]. In code:
Code:
const int maxi = 2, maxj = 3;
int a2Darray[maxi][maxj];
int a1Darray[maxi * maxj];
int x, y;
for(x = 0; x < maxi; x ++) {
for(y = 0; y < maxj; y ++) {
a2Darray[x][y] = x * maxi + y;
a1Darray[x * maxi + y] = x * maxi + y;
}
}
/* a1Darray[] can be initialized in the same way with:
for(x = 0; x < maxi * maxj; x ++) {
a1Darray[x] = x;
}*/
/* So, a2Darray[][] contains:
0, 1,
2, 3,
4, 5
while a1Darray contains:
0, 1, 2, 3, 4, 5
*/
That may have confused you more than it helped, but oh well . . .
should i calculate the sum of each column and row separately and after compare them or must i calculate the sum of the first row and the sum for the first column, compare them and after continue with the others?
It depends on what you are trying to do. I was under the impression that you wanted to sum the entire 1D array, and compare that sum with the sum of the entire 2D array; in which case, summing each row and each column at the same time would make sence.