Obligatory factorial challenge
+3
−0
It looks like we don't have a simple factorial challenge yet, so here's one.
Task
Given a non-negative number, output the factorial of that number ($n!$). The factorial of a number can be defined as such:
$$f(0)=1$$ $$f(n)=n \times f(n-1)$$
Test cases
Input! = Output
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
10! = 3628800
Rules
- The default rules for input and output apply.
- This is [code-golf], so the shortest code in bytes wins!
- Should I delete this draft or put it on hold? Razetime has pointed out that we don't want too many challenges similar to those Somewhere Else, but I thought this'd be a good challenge for beginners.
1 comment thread