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
Model answer
What a good answer should say
- IF x > y THEN OUTPUT x ELSE OUTPUT y
Explanation
Why this works
Selection chooses between alternative paths. This algorithm tests a condition and outputs either x or y.
Common mistake
No common mistake is linked to this question yet.
