equal
deleted
inserted
replaced
4 */ |
4 */ |
5 |
5 |
6 #include <stdio.h> |
6 #include <stdio.h> |
7 #include <stdlib.h> |
7 #include <stdlib.h> |
8 |
8 |
9 unsigned long fak (short i) |
9 unsigned long long fak (short i) |
10 { |
10 { |
11 if (i == 0) |
11 if (i == 0) |
12 return 1; |
12 return 1; |
13 else if (i > 0) |
13 |
14 return (i * fak (i - 1)); |
14 return (i * fak (i - 1)); |
15 else |
15 } |
16 return (i * fak (i + 1)); |
16 |
|
17 long double bigfak (short i) |
|
18 { |
|
19 if (i == 0) |
|
20 return 1; |
|
21 |
|
22 return (i * bigfak (i - 1)); |
17 } |
23 } |
18 |
24 |
19 int main (int argc, char **argv) |
25 int main (int argc, char **argv) |
20 { |
26 { |
21 short number; |
27 short number; |
24 if (scanf ("%hd", &number) != 1) { |
30 if (scanf ("%hd", &number) != 1) { |
25 printf ("READ ERROR\n"); |
31 printf ("READ ERROR\n"); |
26 return EXIT_FAILURE; |
32 return EXIT_FAILURE; |
27 } |
33 } |
28 |
34 |
29 if (number < 0) { |
35 if (number < 0 || number > 170) { |
30 printf ("NUMBER FORMAT ERROR\n"); |
36 printf ("Range Error: %hd ! {0..170}\n", number); |
31 return EXIT_FAILURE; |
37 return EXIT_FAILURE; |
32 } |
38 } |
33 |
39 |
34 printf ("The faktorial of %d is %lu\n", number, fak (number)); |
40 if (number > 20) |
|
41 printf ("The factorial of %2d is %1.5Lg\n", number, bigfak (number)); |
|
42 else |
|
43 printf ("The factorial of %2d is %llu\n", number, fak (number)); |
35 |
44 |
36 return EXIT_SUCCESS; |
45 return EXIT_SUCCESS; |
37 } |
46 } |