Non-tail-recursive implementation of task9-17