Challenge: Factorial
Let’s create a program that calculates factorials using recusion.
We'll cover the following
Problem
For a given value find , where = . 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!
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.