Would you know how to find the max value in a 1-D array, say {3,41,5,6,7} ?
It's exactly the same, only you change the way you index the data, that's all.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Compare
for ( row = 0 ; row < 3 ; row++ )
for ( col = 0 ; col < 5; col++ )
for say averaging each row...
Vs.
for ( col = 0 ; col < 5; col++ )
for ( row = 0 ; row < 3 ; row++ )
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
That's as close as I can get without giving you the answer on a plate.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
now that you have solved it, can you make it more efficient? ie. find the max for each row and each col by making one single pass through the elements of the array.
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
enum { ROWS = 3, COLS = 5 };
const int array[ROWS][COLS] = { /* ... */ } ;
int max_in_row[ROWS] = { /* ... */ }, min_in_row[ROWS] = { /* ... */ },
max_in_col[COLS] = { /* ... */ }, min_in_col[COLS] = {/* ... */ };
for( int row=0 ; row<ROWS ; ++row )
for( int col=0 ; col<COLS ; ++col )
{
// ...
}
// this is the only loop that iterates thru the elements (once).
// at this point you should have arrays max_in_row, min_in_row,
// max_in_col, min_in_col filled with the right values
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287