Factorial
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.)
Factorial
El factorial n! es el producto 1 * 2 * 3 * ... * n. Por definición, 0! es 1.
Inicia un resultado en 1, luego multiplícalo por cada entero desde 2 hasta n dentro de un bucle. (Las pruebas mantienen n como máximo en 10, por lo que la respuesta cabe en un int.)
Complete int factorial(int n) to return n! = 1 * 2 * ... * n. Assume 0 <= n <= 10, and factorial(0) is 1. · Completa int factorial(int n) para que devuelva n! = 1 * 2 * ... * n. Asume 0 <= n <= 10, y factorial(0) es 1.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.