Challenge: Factorial

Let’s create a program that calculates factorials using recusion.

Problem

For a given value nn find n!n!, where n!n! = n(n1)21n * (n-1) \cdots 2*1. Solve this problem using recursion.

Input

A positive integer.

Output

A factorial.

Sample input

5

Sample output

Answer: 120 // 5*4*3*2*1

Coding exercise

Try to solve this yourself first. If you get stuck or need help, you can always press the “Show Solution” button to see how your problem can be solved. We’ll look at the solution in the next lesson.

Good luck!

Get hands-on with 1400+ tech skills courses.