ProgrammingHardCapgemini · TCS NQT Advanced
What will be the output of the following pseudocode? (continue in a do-while loop goes straight to the while test)
What will be the output of the following pseudocode? (continue in a do-while loop goes straight to the while test)
Integer x = 1, c = 0
do
x = x * 3
if (x mod 2 == 1)
x = x + 1
continue
end if
c = c + 1
while (x < 100)
Print x, c- A. 108 3
- B. 122 2
- C. 162 4
- D. 81 3
Correct answer: A. 108 3
In a do-while, continue jumps to the condition test. x: 3 → odd → 4; 12 (even, c = 1); 36 (c = 2); 108 (c = 3), and 108 ≥ 100 ends the loop. Output 108 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? (s[i] - '0' turns a digit character into its value; strings are indexed from 0)…
- What will be the output of the following pseudocode? (+ joins strings) Integer count = 0 String third = "" Procedure gen(String s, Integer…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 49) if (i mod 3 == 0 OR i mod 5 == 0) s = s + i…
- What will be the output of the following pseudocode? (| is OR, & is AND, << and >> are shifts) Integer c = 0, r, x for (each n from 1 to…
- What will be the output of the following pseudocode? Function iso(String a, String b) Map f = empty, g = empty for (each i from 0 to…
- What will be the output of the following pseudocode? (strings are indexed from 0) String s = "AEBCBDA" String t = reverse of s Integer n =…