ProgrammingModerateCapgemini · Infosys pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 10, b = 3, c = 0
while (a >= b)
a = a - b
c = c + 1
end while
Print c, a- A. 4 1
- B. 3 1
- C. 4 -2
- D. 3 0
Correct answer: B. 3 1
Repeated subtraction is division: 10 → 7 → 4 → 1 takes 3 subtractions, and the test 1 >= 3 fails. So c = 3 (the quotient) and a = 1 (the remainder).
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? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 5) for (each j from 1 to 5) if (j > i) break end…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer n = 2048, c = 0, d…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function f(Integer n) if (n…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 3) for (each j from 1 to 3) if (i == j) continue…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…