summaryrefslogtreecommitdiff
path: root/examples/gfcc/factorial.c
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2010-03-02 19:10:56 +0000
committeraarne <aarne@chalmers.se>2010-03-02 19:10:56 +0000
commite4748e998453b979af46983a079f2ec3d307ada4 (patch)
treeef1c2b278850a7f6a95959b6f18469645cf1094c /examples/gfcc/factorial.c
parent21b10f91cbbd0a2d369dc55306bad53df1502cd7 (diff)
restored gfcc example (GF C compiler)
Diffstat (limited to 'examples/gfcc/factorial.c')
-rw-r--r--examples/gfcc/factorial.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/gfcc/factorial.c b/examples/gfcc/factorial.c
new file mode 100644
index 000000000..76fee32d0
--- /dev/null
+++ b/examples/gfcc/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 ;
+} ;
+