annotate paper/src/factrial.cbc @ 35:26c89a10de3c

Update TODO
author atton <atton@cr.ie.u-ryukyu.ac.jp>
date Sat, 28 Jan 2017 09:47:44 +0900
parents 6dedd4ed6b6d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 __code print_factorial(int prod)
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 {
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 printf("factorial = %d\n", prod);
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 exit(0);
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 }
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 __code factorial0(int prod, int x)
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 {
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 if (x >= 1) {
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 goto factorial0(prod*x, x-1);
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 } else {
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 goto print_factorial(prod);
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 }
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 }
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 __code factorial(int x)
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 {
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 goto factorial0(1, x);
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 }
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 int main(int argc, char **argv)
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 {
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 int i;
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 i = atoi(argv[1]);
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 goto factorial(i);
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }
6dedd4ed6b6d Update cbc description
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29