the famous Factorial example
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 30 Jul 2008 00:38:46 +0000 (00:38 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 30 Jul 2008 00:38:46 +0000 (00:38 +0000)
[r20776]

ir/be/test/fak.c [new file with mode: 0644]

diff --git a/ir/be/test/fak.c b/ir/be/test/fak.c
new file mode 100644 (file)
index 0000000..5f971e4
--- /dev/null
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int factorial(int x) {
+       if (x == 0)
+               return 1;
+
+       return x * factorial(x-1);
+}
+
+int main(int argc, char **argv) {
+       int val = atoi(argv[0]);
+       printf("%d\n", factorial(val));
+}