ProgrammingHardAmazon OA · 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}, {4, 5, 6}, {7, 8, 9}}
Integer j
for (each d from 0 to 4)
for (each i from 0 to 2)
j = d - i
if (j >= 0 AND j <= 2)
Print m[i][j]
end if
end for
end for- A. 1 4 2 7 5 3 8 6 9
- B. 1 2 3 4 5 6 7 8 9
- C. 1 2 4 7 5 3 6 8 9
- D. 1 2 4 3 5 7 6 8 9
Correct answer: D. 1 2 4 3 5 7 6 8 9
Cells are visited by anti-diagonal (i + j = d), and within each anti-diagonal by increasing row i: {1}, {2, 4}, {3, 5, 7}, {6, 8}, {9}. Output 1 2 4 3 5 7 6 8 9.
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? (strings are indexed from 0) Procedure perm(String s, Integer l) // s is passed by…
- What will be the output of the following pseudocode? (>> is right shift and & is bitwise AND; (mask >> i) & 1 is evaluated first) Integer…
- What will be the output of the following pseudocode? Integer n = 6, count = 0 Integer col[n] Function ok(Integer r, Integer c) for (each k…
- What will be the output of the following pseudocode? (i++ gives the old value of i and then adds 1) Integer i = 0, c = 0 while (i++ < 5) c…
- What will be the output of the following pseudocode? (--n subtracts 1 from n and then gives the new value) Integer n = 5, s = 0 do s = s +…
- What will be the output of the following pseudocode? (num[i] - '0' converts a digit character to its value) String num = "79927398713"…