Exam-style question
Try this first
Consider the following pseudocode: `x = 10` `y = 5` `IF x > y THEN` `x = x + y` `ELSE` `y = y - x` `END IF` `OUTPUT x` What is the output of this algorithm?.
- A.5
- B.10
- C.15
- D.20
Answer and explanation
Concise answer
15
Why this is correct
Initially, x is 10 and y is 5. Since x (10) is greater than y (5), the IF condition is true. Thus, x becomes x + y, which is 10 + 5 = 15. The algorithm then outputs the value of x, which is 15.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
