What will be the output of the following pseudo code? Integer a, b, c, d, e…
2025
What will be the output of the following pseudo code?
Integer a, b, c, d, e
Set a=50, b=3, c=3, e=0
while(c>0)
d=a mod b
e= e + d + a
c= c - 1
End while
Print e
- A.
52
- B.
100
- C.
156
- D.
153
Attempted by 32 students.
Show answer & explanation
Correct answer: C
Tracing a while loop means executing its body once per pass, in the exact order written, updating each variable as instructed, until the guard condition (c > 0) turns false. Every variable used inside the body -- including an accumulator like e -- must start from an initial value before the loop begins, and that value carries forward, changing only where the body explicitly updates it.
Initial values: a = 50, b = 3, c = 3, e = 0. Since a and b never change inside the loop, d = a mod b is the same in every pass.
Iteration 1: d = 50 mod 3 = 2; e = 0 + 2 + 50 = 52; c becomes 2.
Iteration 2: d = 50 mod 3 = 2; e = 52 + 2 + 50 = 104; c becomes 1.
Iteration 3: d = 50 mod 3 = 2; e = 104 + 2 + 50 = 156; c becomes 0.
Cross-check: because d stays fixed at 2 across all three passes, each pass adds the same (d + a) = 52 to e, so after n passes e = n x 52. The guard c > 0 lets the loop run exactly 3 times (c: 3 to 2 to 1 to 0), so e = 3 x 52 = 156, confirming the step-by-step trace.
The loop then exits (c = 0) and Print e outputs 156.