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

Initial revision
author kono
date Thu, 13 Jan 2000 02:41:41 +0900
parents
children 3db1b6d78412
line wrap: on
line source

#include "stdio.h"

int main( int ac, char *av[])
{
    int n;
    n = atoi(av[1]);
    goto factorial(n,1,n,print,return,environment);
}

code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env)
{
    printf("%d! = %d\n",n, result);
    goto (*exit1)(1),exit1env;
}

code factorial(int n,int result,int orig,code(*print)(),code(*exit1)(),
    void *exit1env)
{
    if (n<0) {
	printf("err %d!\n",n);
	goto (*exit1)(0),exit1env;
    }
    if (n==0)
	goto (*print)(n,result,orig,print,exit1,exit1env);
    else {
	result *= n;
	n--;
	goto factorial(n,result,orig,print,exit1,exit1env);
    }
}