ProgrammingModerateAccenture · Capgemini
What will be the output of the following pseudocode? (Arrays are indexed from 0)
What will be the output of the following pseudocode? (Arrays are indexed from 0)
Integer a[3] = {1, 3, 8}, b[4] = {2, 7, 9, 10}, c[7]
Integer i = 0, j = 0, k = 0
while (i < 3 AND j < 4)
if (a[i] <= b[j])
c[k] = a[i]
i = i + 1
else
c[k] = b[j]
j = j + 1
end if
k = k + 1
end while
while (i < 3) { c[k] = a[i]; i = i + 1; k = k + 1 }
while (j < 4) { c[k] = b[j]; j = j + 1; k = k + 1 }
Print c[3], c[6]- A. 7 10
- B. 8 10
- C. 3 10
- D. 7 9
Correct answer: A. 7 10
Merging gives {1, 2, 3, 7, 8, 9, 10}. The middle (index 3) is 7 and the last is 10: 7 10.
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? Integer m[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} for (each i from 0 to…
- 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)…