Implement the factorial function iteratively and recursively.int FactorialIterative(unsigned int n)
{
if (n == 0 || n == 1)
return 1;
int ret = 1;
while (n > 0)
ret *= n--;
return ret;
}
int FactorialRecursive(unsigned int n)
{
return (n == 0 || n == 1) ? 1 : n * FactorialRecursive(n - 1);
} |