ProgrammingModerateAccenture · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer m[3][3] = {{1, 2, 3}, {2, 5, 9}, {4, 6, 0}}
Integer bad = 0
for (each i from 0 to 2)
for (each j from i + 1 to 2)
if (m[i][j] != m[j][i])
bad = bad + 1
end if
end for
end for
Print bad- A. 4
- B. 3
- C. 1
- D. 2
Correct answer: D. 2
Only the 3 pairs above the diagonal are checked: (0,1): 2 = 2; (0,2): 3 ≠ 4; (1,2): 9 ≠ 6. bad = 2. Checking every (i, j) would count each mismatch twice (4).
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? (operands are evaluated strictly left to right) Integer a = 7, b = 3 a = a + b - (b =…
- What will be the output of the following pseudocode? Integer calls = 0 Function C(Integer n, Integer k) calls = calls + 1 if (k == 0 OR k…
- What will be the output of the following pseudocode? // Integer16: 16-bit signed integers in two's complement; results wrap around…
- What will be the output of the following pseudocode? Record r[4] = {(3, 'a'), (1, 'b'), (3, 'c'), (1, 'd')} // (key, letter) for (each i…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[7] = {4, 2, 2, 8, 3, 3, 1}, cnt[0..8] = all 0…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[8] = {170, 45, 75, 90, 802, 24, 2, 66} List…