Mercurial > hg > Papers > 2010 > kent-master
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/probation-slide/fact.cbc Tue Feb 16 14:48:06 2010 +0900 @@ -0,0 +1,29 @@ +#include<stdio.h> +#define code __code +#define __return _CbC_return +typedef code (*NEXT)(int,void*); + +int main(int argc, char **argv) ; +int factor(int x) ; +code factor0(int prod,int x,NEXT next) ; +code print_fact(int value) ; + + + + +int main(int argc, char **argv) { + int i,a; + i = atoi(argv[1]); + a = factor(i); + printf("%d! = %d\n", a); +} +int factor(int x) { + goto factor0(1, x, __return); +} +code factor0(int prod,int x,NEXT next) { + if (x >= 1) { + goto factor0(prod*x, x-1, next); + } else { + goto (*next)(prod,NULL); + } +}