OLD | NEW |
1 /* | 1 /* |
2 * This simple classical example of recursion is useful for | 2 * This simple classical example of recursion is useful for |
3 * testing stack backtraces and such. | 3 * testing stack backtraces and such. |
4 */ | 4 */ |
5 | 5 |
6 #ifdef vxworks | 6 #ifdef vxworks |
7 | 7 |
8 # include <stdio.h> | 8 # include <stdio.h> |
9 | 9 |
10 /* VxWorks does not supply atoi. */ | 10 /* VxWorks does not supply atoi. */ |
(...skipping 24 matching lines...) Expand all Loading... |
35 #else /* ! vxworks */ | 35 #else /* ! vxworks */ |
36 # include <stdio.h> | 36 # include <stdio.h> |
37 # include <stdlib.h> | 37 # include <stdlib.h> |
38 #endif /* ! vxworks */ | 38 #endif /* ! vxworks */ |
39 | 39 |
40 int main (int argc, char *argv[], char **envp) | 40 int main (int argc, char *argv[], char **envp) |
41 /*int argc; | 41 /*int argc; |
42 char *argv[], **envp;*/ | 42 char *argv[], **envp;*/ |
43 { | 43 { |
44 int factorial (int); | 44 int factorial (int); |
45 #ifdef usestubs | |
46 set_debug_traps(); | |
47 breakpoint(); | |
48 #endif | |
49 #ifdef FAKEARGV | 45 #ifdef FAKEARGV |
50 printf ("%d\n", factorial (1)); | 46 printf ("%d\n", factorial (1)); |
51 #else | 47 #else |
52 if (argc != 2) { | 48 if (argc != 2) { |
53 printf ("usage: factorial <number>\n"); | 49 printf ("usage: factorial <number>\n"); |
54 return 1; | 50 return 1; |
55 } else { | 51 } else { |
56 printf ("%d\n", factorial (atoi (argv[1]))); | 52 printf ("%d\n", factorial (atoi (argv[1]))); |
57 } | 53 } |
58 #endif | 54 #endif |
59 return 0; | 55 return 0; |
60 } | 56 } |
61 | 57 |
62 int factorial (int value) | 58 int factorial (int value) |
63 /*int value;*/ | 59 /*int value;*/ |
64 { | 60 { |
65 int local_var; | 61 int local_var; |
66 | 62 |
67 if (value > 1) { | 63 if (value > 1) { |
68 value *= factorial (value - 1); | 64 value *= factorial (value - 1); |
69 } | 65 } |
70 local_var = value; | 66 local_var = value; |
71 return (value); | 67 return (value); |
72 } | 68 } |
OLD | NEW |