B4Coder

🪆 Recursion · Mission 2 of 5

❗ Factorial

5! (5 factorial) is 5 × 4 × 3 × 2 × 1 = 120. Put another way: 5! is 5 × 4!. A function can use itself for the smaller one.

Your mission

  1. Make a Function called fact, given n.
  2. If n <= 1, Return 1. Otherwise Call fact(n - 1) into smaller, and Return n * smaller.
  3. Main program: Ask for a number into n, Call fact(n) into answer, and Tell n + "! = " + answer.

Getting the mission ready…