Login Register






Factorial Series filter_list
Author
Message
RE: Factorial Series #10
Yes, your code works, but I intentionally avoided this solution. The reason is that I wanted to make cleaner solution, where the only thing that you need to pass to the function is the "n" parameter, everything else is returned value out of the function, it doesn't need any auxiliary ("help") inputs to work correctly.

If you pass incorrect value to the second parameter, it won't work correctly, but you can solve that by creating a "wrapper" instruction.

From practical standpoint, the code you presented is probably better, from "recursive purity" and function isolation, mine is better. Your solution has still traces of the iterative way, just wrapped in a function, meaning it can't work without a helper "counting" variable.

What I also wanted to demonstrate was passing more values from a function.

if(fact) tests if the fact pointer is null or not. If it's null then the condition is false and the assignment won't execute - otherwise the program would crash, because it would try to access invalid place in memory.
I love creativity and creating, I love science and rational thought, I am an open atheist and avid self-learner.

Reply





Messages In This Thread
Factorial Series - by brainfreeezed1 - 11-19-2012, 05:03 AM