Example 49: Calculate a Factorial

Learn how to calculate the factorial of a number using recursion.

Problem

Write a function that uses recursion to calculate the factorial of a number passed as a parameter.

Example

Input Output
5 120
10 3628800

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.