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