I need general explanation of the code:
Case1)
In this factorial function, if num
is 0, then does it return 0!, which is 1?
Case2)
if number is >= than 1, it return fact
, which is it's factorial value?
I understand that return 1
and return 0
is both for successful generation of result.
Then why can't I do return 0, in this case?
double factorial(int num)
{
int fact = 1;
int i = 1;
if (num == 0)
return 1;
else
while (num >= i)
{
fact = fact*i;
i++;
}
return fact;