0
|
1 #include "stdio.h"
|
|
2
|
5
|
3 code factorial(int n,int result,int orig,code(*print)(),code(*exit1)(), void *exit1env)
|
|
4 {
|
|
5 if (n<0) {
|
|
6 printf("err %d!\n",n);
|
|
7 goto (*exit1)(0),exit1env;
|
|
8 }
|
|
9 if (n==0)
|
|
10 goto (*print)(n,result,orig,print,exit1,exit1env);
|
|
11 else {
|
|
12 result *= n;
|
|
13 n--;
|
|
14 goto factorial(n,result,orig,print,exit1,exit1env);
|
|
15 }
|
|
16 }
|
|
17
|
0
|
18 int main( int ac, char *av[])
|
|
19 {
|
|
20 int n;
|
|
21 n = atoi(av[1]);
|
|
22 goto factorial(n,1,n,print,return,environment);
|
|
23 }
|
|
24
|
|
25 code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env)
|
|
26 {
|
53
|
27 printf("%d! = %d\n",orig, result);
|
0
|
28 goto (*exit1)(1),exit1env;
|
|
29 }
|
|
30
|