hi, i have a simple problem with my factorial program.
I can't seem to get my .exe to stay open or when i do i can't input my numbers correctly. Any help with this?
Code:
#include <stdio.h>
void factorial (long number, long *result);
int main (int argc, char *argv[])
{
long argument, result;
if (argc != 2)
{
printf("factorial [long]\n");
return(0);
}
sscanf(argv[1], "%ld", &argument);
factorial(argument, &result);
printf("%1d! = %1d\n", argument, result);
getchar();
}
void factorial (long number, long *result)
{
long temp;
if (number < 2)
*result = 1;
else
{
factorial (number - 1, result);
*result = number * (*result);
}
}
I know this is not the easiest way to do factorial but just ignore that. Also im new to C programming, so thanks for your patience and help.