ProgrammingModerateAccenture · Cognizant GenC Next
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer m[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}
for (each i from 0 to 2)
if (i mod 2 == 0)
for (each j from 0 to 3) Print m[i][j]
else
for (each j from 3 down to 0) Print m[i][j]
end if
end for- A. 1 2 3 4 5 6 7 8 9 10 11 12
- B. 1 2 3 4 8 7 6 5 9 10 11 12
- C. 4 3 2 1 5 6 7 8 12 11 10 9
- D. 1 5 9 10 6 2 3 7 11 12 8 4
Correct answer: B. 1 2 3 4 8 7 6 5 9 10 11 12
Even rows go left to right and odd rows right to left (a snake order): 1 2 3 4, then 8 7 6 5, then 9 10 11 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? (/ is integer division) String tok[9] = {"-", "", "+", "2", "3", "4", "/", "8", "2"}…
- What will be the output of the following pseudocode? Stack s = empty, mins = empty Procedure push2(Integer x) push(s, x) if (mins is empty…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[8] = {1, 3, -1, -3, 5, 3, 6, 7}, k = 3 Deque d…
- What will be the output of the following pseudocode? (& is AND, >> is right shift) Integer x = 23, t = 0 while ((x & 1) == 1) t = t + 1 x…
- What will be the output of the following pseudocode? (& is AND, | is OR, << and >> are shifts) Integer x = 43 Integer y = ((x & 170) >> 1)…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; & is AND, ^ is XOR, | is OR…