ProgrammingHardAmazon OA · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer g[3][4] = {{1, 1, 1, 0}, {1, 1, 1, 1}, {0, 1, 1, 1}}
Integer c = 0
for (each i from 0 to 1)
for (each j from 0 to 2)
if (g[i][j] + g[i][j + 1] + g[i + 1][j] + g[i + 1][j + 1] == 4)
c = c + 1
end if
end for
end for
Print c- A. 6
- B. 5
- C. 4
- D. 2
Correct answer: C. 4
There are 2 × 3 = 6 possible 2 × 2 blocks. Those made entirely of 1's: top row at columns 0–1 and 1–2; bottom row at columns 1–2 and 2–3. c = 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? (All variables are integers, so / is integer division) Function count7(Integer n) if…
- What will be the output of the following pseudocode? String s = "ABCAB" Integer cnt[26] = all 0, total = 0 for (each ch in s) cnt[ch] =…
- What will be the output of the following pseudocode? String s = "COMPUTER" Integer i = 0, j = length(s) - 1 while (i < j) while (i < j AND…
- What will be the output of the following pseudocode? Function isSub(String a, String b) // is b a subsequence of a? Integer j = 0 for…
- What will be the output of the following pseudocode? String s = "ABBACA" Stack st = empty for (each ch in s) if (st not empty AND top(st)…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 3, 4, 5, 6} Integer i = 0, j = 5 while (i < j) if (a[i] mod 2…