annotate test/fact-a.c @ 0:d35df41eac69

Initial revision
author kono
date Thu, 13 Jan 2000 02:41:41 +0900
parents
children 3db1b6d78412
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
d35df41eac69 Initial revision
kono
parents:
diff changeset
3 int main( int ac, char *av[])
d35df41eac69 Initial revision
kono
parents:
diff changeset
4 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
5 int n;
d35df41eac69 Initial revision
kono
parents:
diff changeset
6 n = atoi(av[1]);
d35df41eac69 Initial revision
kono
parents:
diff changeset
7 goto factorial(n,1,n,print,return,environment);
d35df41eac69 Initial revision
kono
parents:
diff changeset
8 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
9
d35df41eac69 Initial revision
kono
parents:
diff changeset
10 code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env)
d35df41eac69 Initial revision
kono
parents:
diff changeset
11 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
12 printf("%d! = %d\n",n, result);
d35df41eac69 Initial revision
kono
parents:
diff changeset
13 goto (*exit1)(1),exit1env;
d35df41eac69 Initial revision
kono
parents:
diff changeset
14 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
15
d35df41eac69 Initial revision
kono
parents:
diff changeset
16 code factorial(int n,int result,int orig,code(*print)(),code(*exit1)(),
d35df41eac69 Initial revision
kono
parents:
diff changeset
17 void *exit1env)
d35df41eac69 Initial revision
kono
parents:
diff changeset
18 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
19 if (n<0) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
20 printf("err %d!\n",n);
d35df41eac69 Initial revision
kono
parents:
diff changeset
21 goto (*exit1)(0),exit1env;
d35df41eac69 Initial revision
kono
parents:
diff changeset
22 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
23 if (n==0)
d35df41eac69 Initial revision
kono
parents:
diff changeset
24 goto (*print)(n,result,orig,print,exit1,exit1env);
d35df41eac69 Initial revision
kono
parents:
diff changeset
25 else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
26 result *= n;
d35df41eac69 Initial revision
kono
parents:
diff changeset
27 n--;
d35df41eac69 Initial revision
kono
parents:
diff changeset
28 goto factorial(n,result,orig,print,exit1,exit1env);
d35df41eac69 Initial revision
kono
parents:
diff changeset
29 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
30 }