The factorial of a number is the product of all the integers from 1 to that number. For example: factorial of 5 is given by 1 × 2 × 3 × 4 × 5 = 120 factorial of 7 is given by 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5040 factorial of 1 = 1 Note: factorial of 0 = 1 A function Factorial() will: • be called with an integer number as a parameter • calculate and return the factorial of the number • return -1 if the number is negative.
- (a)Write pseudocode for the function Factorial().[6]
- (b)A procedure FirstTen () will output the factorial of the numbers from 0 to 9. The procedure will use the function from part (a). The required output is: Factorial of 0 is 1 Factorial of 1 is 1 Factorial of 2 is 2 ... Factorial of 9 is 362880 The program flowchart represents an algorithm for FirstTen(). [Diagram shows flowchart with labels A to F] Complete the table by writing the text that should replace each label A to F. | Label | Text | |---|---| | A | | | B | | | C | | | D | | | E | | | F | |[4]
This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.
Mark scheme
Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.
- [6] (a) Marks as follows to Max 6: 1 Function heading and ending including parameter and return value
- [6] (a) 2 Declaration and initialisation (to 1) of local Integer Value for result
- [6] (a) 3 Check for illegal value (< 0)
- [6] (a) 4 (Conditional) loop while ThisNum not zero // loop for ThisNum iterations
- [6] (a) 5 Attempt to form answer by successive multiplication
- [6] (a) 6 Completely correct MP5
- [6] (a) 7 Return INTEGER value correctly in both cases: ThisNum < 0 and >= 0
- [6] (a) ALTERNATIVE RECURSIVE SOLUTION: 1 Function heading and ending including parameter and return value
- [6] (a) 2 Test for ThisNum > 1 and if so return product of Thisnum and Factorial(ThisNum-1)
- [6] (a) 3 Check for special case...
- [6] (a) 4 ...return 1 for 0 and 1 and return -1 for negative values
- [6] (a) 5 Return INTEGER value (correctly in all cases)
- [4] (b) One mark for: Rows A, B AND C
- [4] (b) Each of rows D, E and F
- [4] (b) A: Is Num > 9?
- [4] (b) B: YES
- [4] (b) C: NO
- [4] (b) D: Set <Identifier> to Factorial (Num)
- [4] (b) E: OUTPUT "Factorial of ", Num, " is ", <Identifier>
- [4] (b) F: Set Num to Num + 1 // Increment Num
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →