|
|
|
|
|
|
|
total = 0;
for (col = 0; col < colLength; col++)
// Invariant (prior to test):
// total == table[row][0] + + table[row][col-1]
// && 0 <= col <= colLength
total = total + table[row][col];
cout << Row sum: << total << endl;
} |
|
|
|
|
|
|
|
|
Figure 13-5 illustrates subarray processing by row. |
|
|
|
|
|
|
|
|
Suppose we want to sum and print each column. The code to perform this task is given below. Again we have generalized the code to sum only the portion of the array that contains valid data. |
|
|
|
|
|
|
|
|
for (col = 0; col < colLength; col++)
{
// Invariant (prior to test):
// Columns 0 through col-1 have been summed and printed
// && 0 <= col <= colLength |
|
|
|
|
|
|
|
|
Figure 13-5
Partial Table Processing by Row |
|
|
|
|
|