annotate test/fact-a.c @ 5:3db1b6d78412

*** empty log message ***
author kono
date Thu, 13 Jan 2000 12:07:28 +0900
parents d35df41eac69
children 64a4e3789fd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1 #include "stdio.h"
d35df41eac69 Initial revision
kono
parents:
diff changeset
2
5
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
3 code factorial(int n,int result,int orig,code(*print)(),code(*exit1)(), void *exit1env)
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
4 {
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
5 if (n<0) {
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
6 printf("err %d!\n",n);
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
7 goto (*exit1)(0),exit1env;
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
8 }
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
9 if (n==0)
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
10 goto (*print)(n,result,orig,print,exit1,exit1env);
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
11 else {
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
12 result *= n;
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
13 n--;
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
14 goto factorial(n,result,orig,print,exit1,exit1env);
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
15 }
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
16 }
3db1b6d78412 *** empty log message ***
kono
parents: 0
diff changeset
17
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
18 int main( int ac, char *av[])
d35df41eac69 Initial revision
kono
parents:
diff changeset
19 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
20 int n;
d35df41eac69 Initial revision
kono
parents:
diff changeset
21 n = atoi(av[1]);
d35df41eac69 Initial revision
kono
parents:
diff changeset
22 goto factorial(n,1,n,print,return,environment);
d35df41eac69 Initial revision
kono
parents:
diff changeset
23 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
24
d35df41eac69 Initial revision
kono
parents:
diff changeset
25 code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env)
d35df41eac69 Initial revision
kono
parents:
diff changeset
26 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
27 printf("%d! = %d\n",n, result);
d35df41eac69 Initial revision
kono
parents:
diff changeset
28 goto (*exit1)(1),exit1env;
d35df41eac69 Initial revision
kono
parents:
diff changeset
29 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
30