Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 3, 2019 06:55
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/944d344fa831d23ce9d91d1054f3d6cd to your computer and use it in GitHub Desktop.
Save parzibyte/944d344fa831d23ce9d91d1054f3d6cd to your computer and use it in GitHub Desktop.
/**
* Factorial de un número en C. Usando recursión / recursividad
*
* @author parzibyte
* @see https://parzibyte.me/blog
* */
#include <stdio.h>
unsigned long long factorial(unsigned long long numero) {
// Si hemos llegado a 1, detenemos la recursión
if (numero <= 1)
return 1;
return numero * factorial(numero - 1); // Restar 1
}
int main(void) {
unsigned long long numero = 5;
unsigned long long factorialDelNumero = factorial(numero);
printf("El factorial de %llu es %llu", numero, factorialDelNumero);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment