Challenge 11

Factorial

Open in Code Editor or Copy Instructions
...solutions at bottom of page...

Create a program to calculate the factorial of a number. For example:

Examples:

the factorial of 5 is 5 * 4 * 3 * 2 * 1 = 120

the factorial of 7 is 7 * 6 * 5 * 4 * 3 * 2 * 1 = 5040

Note the 'special' case, where factorial of 0 is 1

Extension:

  • Output the factorial of each number from 0 to 100
  • For A2 students - or others that are curious - implement the factorial function both iteratively and recursively

Solutions

IGCSE 0478 / O-Level 2210 A-Level 9618