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- A. 58 12
- B. 154 18
- C. 139 12
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? Function J(Integer n, Integer k) if (n == 1) return 0 end if return (J(n - 1, k) + k)…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function gcd(Integer a…
- What will be the output of the following pseudocode? Function sd(Integer n) Integer s = 0 for (each d from 1 to n - 1) if (n mod d == 0) s…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings) String digits…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code and char(k) the reverse) String s =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; arrays are indexed from 0)…