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

*** empty log message ***
author kono
date Thu, 13 Jan 2000 12:07:28 +0900
parents d35df41eac69
children 64a4e3789fd2
comparison
equal deleted inserted replaced
4:535bf528d68f 5:3db1b6d78412
1 #include "stdio.h" 1 #include "stdio.h"
2
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 }
2 17
3 int main( int ac, char *av[]) 18 int main( int ac, char *av[])
4 { 19 {
5 int n; 20 int n;
6 n = atoi(av[1]); 21 n = atoi(av[1]);
11 { 26 {
12 printf("%d! = %d\n",n, result); 27 printf("%d! = %d\n",n, result);
13 goto (*exit1)(1),exit1env; 28 goto (*exit1)(1),exit1env;
14 } 29 }
15 30
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 }