/* For all the functions below, return TRUE if the
calculation is successful, FALSE if overflow occurs
Return the calculated value in the pass by reference
parameter provided
*/
Boolean calcFactorial (int n, int* nfact)
{
unsigned long int count = 1;
unsigned long int result = 1;
while(count <= n)
{
if(*nfact <= 0) // not sure about this.
{
return FALSE;
}
else
{
result = result * count;
count++;
}
}
return TRUE;
}
Factorial is: n! = n * (n-1) * (n-2) * . . . * 3 * 2 * 1
Can someone please check if my coding is correct, especially the "if(*nfact <= 0)" which is checking for overflow ?