Follow your books suggestion, so you can see the logic in the recursion.
int factorial(int number)
{
if (number <= 1)
return 1;
else
{
std::cout << number << " * " << "factorial(" << number << " - 1)" << std::endl;
return number * factorial(number - 1);
}
}
The flow will be:
4 * factorial(4 - 1)
3 * factorial(3 - 1)
2 * factorial(2 - 1)
Answer: 24
Mathematically the factorial of 4, would equate to:
4 × 3 × 2 × 1 = 24
Do you see the pattern?