Mathematics I / Recursion
Practice question · Numerical answer

The factorial is defined by fact(n) = n * fact(n-1) with fact(0) = 1. Compute fact(5).

Hints
  1. Unwind to the base case, then multiply back up.
  2. fact(4) is 24.
Show the answer

120

Why

5 4 3 2 1 = 120, with the base case contributing the final factor 1. Checking a recursive definition on a small value you can verify by hand is the same sanity check a base case performs in an induction proof.

Read the lesson: Recursion →

Practise Recursion

The app has 6 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.

More questions on Recursion