ProgrammingHardAccenture · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer r[3][4] = {{1, 2, 3, 4}, {2, 4, 6, 8}, {4, 2, 5, 1}}
Integer c = 0
for (each j from 0 to 3)
Integer v = r[0][j]
Boolean inAll = true
for (each i from 1 to 2)
if (v does not occur in row i) inAll = false
end for
if (inAll) c = c + 1
end for
Print c- A. 1
- B. 2
- C. 3
- D. 4
Correct answer: B. 2
Only values of row 0 that also appear in rows 1 and 2 count: 1 is missing from row 1 and 3 from both, while 2 and 4 are in every row. c = 2.
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? // list: 10 -> 20 -> 30 -> 40 -> 50 -> NULL Node fast = head, slow = head Integer k =…
- What will be the output of the following pseudocode? Integer a[7] = {10, 5, 3, 4, 3, 5, 6} Set seen = empty Integer first = -1 for (each i…
- What is the time complexity of the following pseudocode, as a function of n? for (each i from 1 to n) for (each j from 1 to n) if (i == j)…
- Strings are immutable here, so s = s + "a" copies the whole current string. What is the time complexity of the following pseudocode, as a…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Boolean prime[2..50] //…
- What will be the output of the following pseudocode? Integer count = 0, n = 2, s = 0 while (count < 10) Boolean pr = true for (each d from…