Factorial · Fatorial
Factorial
The factorial n! is the product 1 * 2 * 3 * ... * n. By definition 0! is 1.
Start a result at 1, then multiply it by every integer from 2 up to n in a loop. (The tests keep n at most 10, so the answer fits in an int.)
Fatorial
O fatorial n! é o produto 1 * 2 * 3 * ... * n. Por definição 0! é 1.
Inicie um resultado em 1, depois multiplique-o por cada inteiro de 2 até n em um loop. (Os testes mantêm n no máximo 10, então a resposta cabe em um int.)
Complete int factorial(int n) to return n! = 1 * 2 * ... * n. Assume 0 <= n <= 10, and factorial(0) is 1. · Complete int factorial(int n) para retornar n! = 1 * 2 * ... * n. Assuma 0 <= n <= 10, e factorial(0) é 1.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.