Mercurial > hg > CbC > old > device
comparison test/fact.c @ 0:d35df41eac69
Initial revision
author | kono |
---|---|
date | Thu, 13 Jan 2000 02:41:41 +0900 |
parents | |
children | e2c2c0fe0785 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d35df41eac69 |
---|---|
1 #include "stdio.h" | |
2 | |
3 int | |
4 main(ac,av) | |
5 int ac; | |
6 char *av[]; | |
7 { | |
8 int n; | |
9 n = atoi(av[1]); | |
10 goto factorial(n,1,n,print,return,environment); | |
11 } | |
12 | |
13 code print(n,result,orig,print,exit1,exit1env) | |
14 int n,result,orig; | |
15 code (*print)(),(*exit1)(); | |
16 void *exit1env; | |
17 { | |
18 printf("%d! = %d\n",n, result); | |
19 goto (*exit1)(1),exit1env; | |
20 } | |
21 | |
22 code factorial(n,result,orig,print,exit1,exit1env) | |
23 int n,result,orig; | |
24 code (*print)(); | |
25 code (*exit1)(); | |
26 void *exit1env; | |
27 { | |
28 if (n<0) { | |
29 printf("err %d!\n",n); | |
30 goto (*exit1)(0),exit1env; | |
31 } | |
32 if (n==0) | |
33 goto (*print)(n,result,orig,print,exit1,exit1env); | |
34 else { | |
35 result *= n; | |
36 n--; | |
37 goto factorial(n,result,orig,print,exit1,exit1env); | |
38 } | |
39 } |