Factorial
Inputs
n is a whole number from 0 to 10.
Your tasks
- Create a number
productthat starts at 1. - Use a loop to multiply
productby each whole number from 1 up to and includingn. - Complete
factorialso it returnsproduct. Return it, do not print it.
Example
With n = 5, factorial returns 120.
Rules
- The product of no numbers is 1, so
factorial(0)is 1.
Test data
TEST DATA 1: n is 5
TEST DATA 2: n is 0
Practice focus
Loops that count, add up and multiply. Every algorithm starts here: a counter, a total and a stopping point.