Problem with Recursion calculing Factorials
Well, I've been learning those things that I didn't knew in theC tutorial of this site, and, in the recursion chapter, there was a homework where you had to write a program which calculates factorials.
This is my function:
I call the function from main this way:
int ObtenerFactorial( int num, int count, int result )
if ( count==num ) return result;
result *= (num-count);
ObtenerFactorial( num, count+1, result );
Where 'number' is entered throw the command line.
scanf( "%d", &number );
factorial = ObtenerFactorial( (int)number, 0, 1 );
printf( "\nFactorial de %d: %d\n", number, factorial);
When the user enter 0, the result is fine, 1. But when you enter any number greater than 0 (1,5,etc), everytimes get out the same result: 1075144832. I don't know what is the problem... I don't expect that you write my homework, just to tell what's wrong: if it's all wrong, I'll write a new program.