view test/fact-a.c @ 492:cc1a5f764782

*** empty log message ***
author kono
date Wed, 21 Dec 2005 12:10:43 +0900
parents 0c256ea2a97e
children 388baa7d4bee
line wrap: on
line source

#include "stdio.h"

code factorial(int n,int result,int orig,code(*print)(),code(*exit1)(), void *exit1env)
{
    if (n<0) {
	printf("#0005: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);
    }
}

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

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