Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 3, 2019 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3d3796d85ca1aa85187d3eb612f0b389 to your computer and use it in GitHub Desktop.
Save parzibyte/3d3796d85ca1aa85187d3eb612f0b389 to your computer and use it in GitHub Desktop.
unsigned long long factorial(unsigned long long numero) {
// Convertir a positivo si es necesario
if (numero < 0)
numero = numero * -1;
// Si es 0, el factorial es 1
if (numero == 0)
return 1;
// Si ninguna condición anterior se cumple, multiplicamos
unsigned long long factorial = 1;
while (numero > 1) {
factorial = factorial * numero;
numero--;
}
return factorial;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment