diff paper/src/factrial.cbc @ 15:6dedd4ed6b6d

Update cbc description
author atton <atton@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Jan 2017 11:39:10 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/factrial.cbc	Thu Jan 19 11:39:10 2017 +0900
@@ -0,0 +1,29 @@
+__code print_factorial(int prod)
+{
+  printf("factorial = %d\n", prod);
+  exit(0);
+}
+
+__code factorial0(int prod, int x)
+{
+  if (x >= 1) {
+    goto factorial0(prod*x, x-1);
+  } else {
+    goto print_factorial(prod);
+  }
+
+}
+
+__code factorial(int x)
+{
+  goto factorial0(1, x);
+}
+
+int main(int argc, char **argv)
+{
+  int i;
+  i = atoi(argv[1]);
+
+  goto factorial(i);
+}
+