- Joined
- Jun 14, 2021
- Messages
- 6
- Reaction score
- 0
My factorial program does not give me the correct results in cases, for instance 13 should be 6227020800 and my output is 1932053504. I display my C program below, is someone able to help me fix it for these cases? I know the formula for factorial is n × (n - 1).
C:
int factorial(int nb)
{
int res;
int i;
res = 1;
i = 1;
if (nb == 0 || nb == 1)
return (1);
while (++i <= nb)
{
res *= i;
}
return (res);
}
Last edited: