web: home-page: Add tcc.html to index.html
[lcapit-junk-code.git] / factorial.c
blobbaf36617dc0819083d8bb82d629c2e123aa0a3c6
1 /*
2 * factorial: Calculate's a number factorial
3 */
4 #include <stdio.h>
5 #include <stdlib.h>
7 long double factorial(long n)
9 int i;
10 long double m;
12 for (m = 1, i = n; i > 1; i -= 1)
13 m *= i;
15 return m;
18 int main(int argc, char *argv[])
20 long n;
21 long double f;
23 if (argc != 2) {
24 printf("Usage: %s < number >\n", argv[0]);
25 exit(1);
28 n = strtol(argv[1], NULL, 10);
29 /* FIXME: Error checking */
31 f = factorial(n);
32 if (!f) {
33 /* FIXME: Explain why */
34 fprintf(stderr, "Could not caculate the factorial\n");
35 exit(1);
38 printf("%ld! = %Le\n", n, f);
40 return 0;