ProgrammingModerateTCS NQT · Accenture

What will be the output of the following pseudocode? (Arrays are indexed from 0)

What will be the output of the following pseudocode? (Arrays are indexed from 0)
Integer A[2][3] = {{1, 2, 3}, {4, 5, 6}}
Integer Bm[3][2] = {{7, 8}, {9, 10}, {11, 12}}
Integer C[2][2] = all 0, mults = 0
for (each i from 0 to 1)
    for (each j from 0 to 1)
        for (each k from 0 to 2)
            C[i][j] = C[i][j] + A[i][k] * Bm[k][j]
            mults = mults + 1
        end for
    end for
end for
Print C[1][0], mults
  1. A. 58 12
  2. B. 154 18
  3. C. 139 12
  4. D. 139 6

Correct answer: C. 139 12

C[1][0] is row 2 of A times column 1 of B: 4 × 7 + 5 × 9 + 6 × 11 = 28 + 45 + 66 = 139. A 2×3 by 3×2 product needs 2 × 2 × 3 = 12 multiplications: 139 12.

More Pseudocode and Code Tracing questions

Exams that ask this topic