What will be the output of the following pseudo code for a = 0, b = 3?
Accenture technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What will be the output of the following pseudo code for a = 0, b = 3?
Integer funn(Integer a, Integer b)
if ((4 - b) < (b - a) && b > a)
a = 3 + 3 + a
a = 2 + 1 + a
End if
return a + b
Show answer & explanation
Answer: A. 12
The if condition evaluates to true: (4 - 3) < (3 - 0) simplifies to 1 < 3 (true) AND 3 > 0 (true). Both statements execute: a becomes 6, then a becomes 9. The function returns a + b = 9 + 3 = 12.
Step-by-step Derivation:
Step 1: Initial values: a = 0, b = 3
Step 2: Evaluate condition:
- (4 - b) < (b - a): (4 - 3) < (3 - 0) → 1 < 3 → true
- b > a: 3 > 0 → true
- Combined with &&: true && true → true
Step 3: Execute if block: - First: a = 3 + 3 + a = 3 + 3 + 0 = 6
- Second: a = 2 + 1 + a = 2 + 1 + 6 = 9
Step 4: Return a + b = 9 + 3 = 12