The nonrecursive function is in the file iterativeFactorial.cpp .
The code is given below.
int factorial(int n)
{// Return n!.
if (n <= 1)
return 1;
int fact = 2;
for (int i = 3; i <= n; i++)
fact *= i;
return fact;
}
Sfactorial(n) = 0
while the
space requirements of the recursive version are 8 * max{n, 1} (see Example 2.5).
The nonrecursive version
uses less space than its recursive counterpart.