home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1993 #2
/
Image.iso
/
wp
/
be310a.zip
/
FACT.CHS
< prev
next >
Wrap
Text File
|
1993-08-01
|
1KB
|
32 lines
/* CHESS FUNCTION(S): FACT.CHS -- standalone Chess program
/* DATE: 07-10-93
/* AUTHOR: C. Schanck
/*
/* DESCRIPTION: this does a factorial generation -- useful as an
/* example of recursion
/*
/* This function uncovered a bug in v3.10's parsing routines.
{
char temp[30];
int i;
temp[0]=0;
if((get_str(temp,"Find factorial of What number (1-12)?",2)%256)!=27){
/* if the user didn't press escape
i=atoi(temp); /* convert to an integer
i=do_fact(i); /* find its factorial
msg("%s factorial is %ld",temp,i); /* print it out
getkey(); /* wait for a keypress
update_display();
}
}
do_fact /* this function is a recursive one
int n; /* single parameter
{
if((n<1)||(n>12)) /* if illegal, return 0
return(0);
else if(n==1) /* if we are done with recursive call
return(1);
else /* else, recurse another level
return(do_fact(n-1)*n);
}