annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include<stdio.h>
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #define code __code
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #define __return _CbC_return
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 typedef code (*NEXT)(int,void*);
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 int main(int argc, char **argv) ;
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 int factor(int x) ;
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 code factor0(int prod,int x,NEXT next) ;
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 code print_fact(int value) ;
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 int main(int argc, char **argv) {
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 int i,a;
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 i = atoi(argv[1]);
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 a = factor(i);
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 printf("%d! = %d\n", a);
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 }
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 int factor(int x) {
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 goto factor0(1, x, __return);
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 code factor0(int prod,int x,NEXT next) {
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 if (x >= 1) {
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 goto factor0(prod*x, x-1, next);
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 } else {
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 goto (*next)(prod,NULL);
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }
12cb508ee15d add slides for probation.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }