The factorial n! = 1 × 2 × … × n, and 0! = 1. This time, no loop: use recursion to write fact(n). n! is n × (n-1)!, so 5! = 5 × 4! = 120. The starter already returns 1 when n is 0 or 1; you write the last line.
fact(5)→120fact(0)→1fact(3)→6long long fact(int n)long long fact(int n) {
if (n <= 1) {
return 1;
}
// your code here: return n times the factorial of (n-1)
return 0;
}
Run tries the examples. When they look right, Submit.