I have the following code in C++
int factorial_recursivo(int factorial) {
if(factorial <= 1) return 1;
// To show all the factors in each iteration std::cout << factorial << std::endl;
return factorial * factorial_recursivo(--factorial);
}
However, if i write a number n, the result is the factorial of the number n-1.
If i change the last line of code the factorial_recursivo(--factorial)
by factorial_recursivo(factorial - 1)
works properly.
Why this happen? I even printed the factors in console and it correctly showed. Per example, with factoria_recursivo(5)
i got 5 4 3 2, however the result was 24.