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:
Code:
int ObtenerFactorial( int num, int count, int result )
{
if ( count==num ) return result;
else
{
result *= (num-count);
ObtenerFactorial( num, count+1, result );
}
}
I call the function from main this way:
Code:
fflush(stdin);
scanf( "%d", &number );
factorial = ObtenerFactorial( (int)number, 0, 1 );
printf( "\nFactorial de %d: %d\n", number, factorial);
Where 'number' is entered throw the command line.
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.