diff options
Diffstat (limited to 'reference/C/CONTRIB/OR_USING_C/02.4.c')
-rw-r--r-- | reference/C/CONTRIB/OR_USING_C/02.4.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/OR_USING_C/02.4.c b/reference/C/CONTRIB/OR_USING_C/02.4.c new file mode 100644 index 0000000..4f2dd28 --- /dev/null +++ b/reference/C/CONTRIB/OR_USING_C/02.4.c @@ -0,0 +1,23 @@ +#include <stdio.h> + +main() +{ + int n, m; + + printf("Enter a number: "); + scanf("%d", &n); + + m = fact(n); + printf("The factorial of %d is %d.\n", n, m); + exit(0); +} + +fact(n) +int n; +{ + if (n == 0) + return(1); + + return(n * fact(n-1)); +} + |