Factorial (mind the size) · Fatorial (cuidado com o tamanho)
Factorial (mind the size)
n! is 1 × 2 × … × n, and 0! is 1. It grows fast — 20! is over two billion billion — so the method returns a long, not an int, or the answer would overflow. Multiply from 2 up to n.
Fatorial (cuidado com o tamanho)
n! é 1 × 2 × … × n, e 0! é 1. Cresce rápido — 20! é mais de dois bilhões de bilhões — então o método retorna um long, não um int, ou a resposta transbordaria. Multiplique de 2 até n.
Complete factorial(int n) returning n! as a long (so large values fit). factorial(0) is 1. Assume 0 <= n <= 20. · Complete factorial(int n) retornando n! como long (para que valores grandes caibam). factorial(0) é 1. Assuma 0 <= n <= 20.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.