next up previous
Next: Implied Do loops Up: CS101 Lecture 10 Previous: CS101 Lecture 10

Sample Problem using 2-D arrays

English Description

Read in a 2-D array (4x3) of postive integers. Find which row has maximum sum and print that row and its sum.

Sample Example

   row 1:    8   9   12         sum = 29  
   row 2:    2  23   16         sum = 41
   row 3:    11  8   23         sum = 42
   row 4:    7   3   44         sum = 54

Algoritm
  1. Read in the array (what is input format?)
  2. Initialize MaxRow and MaxSum to 0 (is this a good idea?)
  3. Loop row-by-row
    1. compute sum of this row
    2. compare with MaxSum
    3. Reset MaxSum and MaxRow if necessary
  4. Print the answer (how to get on one line?)



G. Sivakumar 2000-08-23