Exam-style question
Try this first
Which pseudocode uses selection to output the larger of two values, x and y?.
- A.OUTPUT x + y
- B.IF x > y THEN OUTPUT x ELSE OUTPUT y
- C.FOR count <- 1 TO x OUTPUT y NEXT count
- D.larger <- x + y
Answer and explanation
Concise answer
IF x > y THEN OUTPUT x ELSE OUTPUT y
Why this is correct
Selection chooses between alternative paths. This algorithm tests a condition and outputs either x or y.
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.
