home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
spoc88
/
factrl
/
factorl.c
< prev
Wrap
Text File
|
1988-06-21
|
545b
|
31 lines
/* FACTORL.C: Computes factorial of a keyed number */
/* Repeats until user enters 0 */
#include <stdio.h>
main ()
{
int value, atoi();
long fact();
char input [6];
do {
printf ("\nValue? ");
gets (input);
value = atoi (input);
if (value > 0)
printf ("\nFactorial = %ld\n", fact (value));
else
puts ("\nCannot take factorial of negative number\n");
} while (value);
}
long fact (int val)
{
long result = 0;
if (val)
result = val * fact (val-1);
return (result);
}