Exercises

Exercise 1

Last time, we implemented a factorial function using recursion. As a reminder, a factorial multiplies all the numbers from 1 to the target, so fact(5) == 1 * 2 * 3 * 4 * 5. Write a fact function using iteration and a while loop instead of recursion.

Get hands-on with 1400+ tech skills courses.