Question 4
OCR Computer Science June 2022 Algorithms and problem solving (H046-02)AS6 marks
On the specification
- (a)
- 2.2 Problem solving and programming
- (b)
- 2.3 Algorithms
- (c)
- 2.3 Algorithms
- (d)
- 2.2 Problem solving and programming
Question text
4 Given the following procedure: 1 procedure generate(number) 2 a = 0 3 while number > 0 4 if number MOD 2 == 0 then 5 a = a + 2 6 print(a) 7 number = number – 2 8 else 9 a = a + 1 10 print(a) 11 number = number – 1 12 endif 13 endwhile 14 endprocedure (a) Explain why = is used on line 11 of the procedure generate instead of ==. [2] (b) State the values printed by the procedure generate when number = 8. [1] (c) State the values printed by the procedure generate when number = 7. [1] (d) Describe the purpose of the MOD operator on line 04 of the procedure generate. [2]