annotate final_pre/src/factrial.cbc @ 7:0e8b9646d43f

add final_pre
author e155702
date Sun, 17 Feb 2019 05:39:59 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
1 __code print_factorial(int prod)
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
2 {
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
3 printf("factorial = %d\n", prod);
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
4 exit(0);
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
5 }
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
6
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
7 __code factorial0(int prod, int x)
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
8 {
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
9 if (x >= 1) {
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
10 goto factorial0(prod*x, x-1);
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
11 } else {
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
12 goto print_factorial(prod);
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
13 }
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
14
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
15 }
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
16
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
17 __code factorial(int x)
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
18 {
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
19 goto factorial0(1, x);
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
20 }
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
21
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
22 int main(int argc, char **argv)
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
23 {
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
24 int i;
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
25 i = atoi(argv[1]);
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
26
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
27 goto factorial(i);
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
28 }
0e8b9646d43f add final_pre
e155702
parents:
diff changeset
29