Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // Iterative
- long long int factorielle(int n)
- {
- long long int x = 1;
- for(n; n > 0; n--)
- x *= n;
- return x;
- }
- // Récursive
- int factorielleR(int n)
- {
- if(n == 1 || n == 0)
- return 1;
- else if (n < 0)
- exit(EXIT_FAILURE);
- return n * factorielleR(n - 1);
- }
- int main()
- {
- int i;
- // Le résultat devient faux à partir de 17! (inclus) en utilisant un int.
- // On peut remplacer int factorielle(int n) par long long int factorielle(int n)
- // On peut aussi utiliser la Librairie GMP disponible sur https://gmplib.org
- for(i = 0; i < 100; i++)
- printf("%d! = %lld\n", i, factorielle(i));
- // Récursive
- printf("10! = %d\n", factorielleR(10));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement