ProgrammingModerateTCS NQT · Infosys · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer i = 10, c = 0
do
i = i - 4
c = c + 1
while (i > 0)
Print i, c- A. 2 2
- B. -2 3
- C. -2 2
- D. 6 3
Correct answer: B. -2 3
i goes 6, 2, -2; the condition is tested after the body, so the loop ends once i = -2 after three passes.
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? function g(Integer n) if (n > 0) g(n - 1) Print n g(n - 2) end if end function g(3)
- What will be the output of the following pseudocode? Integer c = 0 for (i = 100; i > 1; i = i / 3) c = c + 1 end for Print c
- What will be the output of the following pseudocode? (All variables are integers.) Integer a = 9, b = 2 a = a b b = a / b a = a / b Print…
- What will be the output of the following pseudocode? Integer i, s = 0 for (i = 1; i <= 20; i = i + 3) s = s + i end for Print s
- What will be the output of the following pseudocode? Integer a = 5, b = 9 a = a ^ b b = a ^ b a = a ^ b Print a 10 + b
- What will be the output of the following pseudocode? Integer i, j, c = 0 for (i = 1; i <= 6; i = i + 1) for (j = 1; j <= 6; j = j + 1) if…