< previous page page_717 next page >

Page 717
    total = 0;
    for (row = 0; row < rowLength; row++)

            // Invariant (prior to test):
            //     total == table[0][col] +  + table[row-1][col]
            // && 0 <= row <= rowLength

        total = total + table[row][col];
    cout << Column sum:  << total << endl;
}
In this case, the outer loop controls the column, and the inner loop controls the row. All the components in the first column are accessed and summed before the outer loop index changes and the components in the second column are accessed. Figure 136 illustrates subarray processing by column.
Initialize the Table
As with one-dimensional arrays, we can initialize a two-dimensional array either by initializing it in its declaration or by using assignment statements. If the array is small, it is simplest to initialize it in its declaration. To initialize a 2-row by 3-column table to look like this:
14   3  -5
 0  46   7
0717-01.gif
Figure 13-6
Partial Table Processing by Column

 
< previous page page_717 next page >