Create a recursive
countdown function that takes in an integer
n and prints out a countdown from n to 1.
First, think about a base case for the
What is the simplest input the problem could be given?
The simpleset input is where there is no need to count down! That is, when
n == 1 we simply print out 1.
After you’ve thought of a base case, think about a recursive call with a smaller argument that approaches the base case.
Need a hint?
What happens if you call
countdown(n - 1)?
Then, put the base case and the recursive call together, and think about where a print statement would be needed.