Mercurial > hg > Papers > 2010 > kent-master
comparison probation-slide/fact.cbc @ 13:12cb508ee15d after-organizing
add slides for probation.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 16 Feb 2010 14:48:06 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
12:0f9a0ecc6afb | 13:12cb508ee15d |
---|---|
1 #include<stdio.h> | |
2 #define code __code | |
3 #define __return _CbC_return | |
4 typedef code (*NEXT)(int,void*); | |
5 | |
6 int main(int argc, char **argv) ; | |
7 int factor(int x) ; | |
8 code factor0(int prod,int x,NEXT next) ; | |
9 code print_fact(int value) ; | |
10 | |
11 | |
12 | |
13 | |
14 int main(int argc, char **argv) { | |
15 int i,a; | |
16 i = atoi(argv[1]); | |
17 a = factor(i); | |
18 printf("%d! = %d\n", a); | |
19 } | |
20 int factor(int x) { | |
21 goto factor0(1, x, __return); | |
22 } | |
23 code factor0(int prod,int x,NEXT next) { | |
24 if (x >= 1) { | |
25 goto factor0(prod*x, x-1, next); | |
26 } else { | |
27 goto (*next)(prod,NULL); | |
28 } | |
29 } |