Created
December 3, 2019 06:55
-
-
Save parzibyte/944d344fa831d23ce9d91d1054f3d6cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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