9
Calculer une factorielle
- #include <stdio.h>
- #define NFACT 6
- main() {
- int n = 6;
- int f = 1;
- do {
- f *= n;
- --n;
- } while ( n > 1);
- printf("%d! = %d\n", NFACT, f);
- }
$ gcc -o fact fact.c
$ ./fact
6! = 720
$ gcc -o fact fact.c
$ ./fact
6! = 720
Commentaires