Factorial algorithm using iteration