ProgrammingModerateTCS NQT · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 20, b = 6, c = 0
while (a > b)
a = a - 3
b = b + 2
c = c + 1
end while
Print a, b, c- A. 14 10 2
- B. 8 14 4
- C. 12 12 3
- D. 11 12 3
Correct answer: D. 11 12 3
The gap a − b shrinks by 5 each pass: 14, 9, 4, −1. After 3 passes a = 11 and b = 12, so a > b fails: 11 12 3.
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 r[3][4] = {{1, 2, 3, 4}, {2, 4, 6, 8}, {4, 2, 5, 1}} Integer c = 0 for (each…
- 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] //…