What will be the output of the following pseudo code? Input m = 9, n = 6 , m =…
2023
What will be the output of the following pseudo code?
Input m = 9, n = 6 ,
m = m + 1 ;
n = n - 1 ;
m = m + n
if (m > n)
print m
else
print n
- A.
6
- B.
5
- C.
10
- D.
15
Show answer & explanation
Correct answer: D
In sequential pseudocode, each assignment statement redefines a variable using the values that already exist at that point in the trace; the if-else condition is then evaluated using the FINAL values reached after every preceding statement has executed, and only the branch it selects prints its variable.
Tracing the given code step by step:
Initialise m = 9 and n = 6.
m = m + 1, so m becomes 9 + 1 = 10.
n = n - 1, so n becomes 6 - 1 = 5.
m = m + n, so m becomes 10 + 5 = 15.
Evaluate the condition: is m > n? That is, is 15 > 5? — true.
Since the condition is true, the if-branch runs: print m.
Cross-check: substituting the final values m = 15 and n = 5 back into the condition confirms 15 > 5 holds, and because only one branch of an if-else ever executes, the program prints m alone — not n, and not any of the intermediate values reached along the way.
Hence the output printed is 15.