diff options
Diffstat (limited to 'old-examples/gfcc/compiler/factorial.c')
| -rw-r--r-- | old-examples/gfcc/compiler/factorial.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/old-examples/gfcc/compiler/factorial.c b/old-examples/gfcc/compiler/factorial.c new file mode 100644 index 000000000..76fee32d0 --- /dev/null +++ b/old-examples/gfcc/compiler/factorial.c @@ -0,0 +1,38 @@ +int fact (int n) { + int f ; + f = 1 ; + { + while (1 < n) { + f = n * f ; + n = n - 1 ; + } + } + return f ; +} ; + +int factr (int n) { + int f ; + { + if (n < 2) { + f = 1 ; + } + else { + f = n * factr (n-1) ; + } + } + return f ; +} ; + +int main () { + int n ; + n = 1 ; + { + while (n < 11) { + printf("%d",fact(n)) ; + printf("%d",factr(n)) ; + n = n+1 ; + } + } + return ; +} ; + |
