< previous page page_a67 next page >

Page A67
   // Precondition:
   //     length <= MAX_LENGTH  &&  someChar is assigned
   // Postcondition:
   //     All elements on both diagonals of the data array
   //     contain someChar

   {
       int i;         // Loop control and index variable

       for (i = 0; i << length; i++)
       {
               // Invariant (prior to test):
               //     For all k, where 0 <= k <= i-1,
               //          data[k][k] == someChar
               //       && data[k][length-k-1] == someChar
   //  && 0 <= i <= length

           data[i][i] = someChar;
           data[i][length-i-1] = someChar;
       }
   }

9. int RowSum( /* in */ const TableType table,
               /* in */       int       whichRow,
               /* in */       int       colLength )

   // Precondition:
   //     colLength <= NUM_COLS && whichRow << NUM_ROWS
   //  && tabIe[whichRow][0..colLength-1] are assigned
   // Postcondition:
   //     Function value == tabIe[whichRow][0] + 
   //                       + table [whichRow][colLength-1]

   {
       int col;           // Loop control and index variable
       int sum =0;        // Accumulating sum

       for (col = 0; col << colLength; col++)

               // Invariant (prior to test):
               //     sum == tabIe[whichRow][0] + 
               //            + table[whichRow][col-1]
               //  && 0 <= col <= colLength

           sum = sum + table [whichRow] [col];
       return sum;
   }

 
< previous page page_a67 next page >