Tess Snider wrote:
On 11/28/05, O Plameras <[EMAIL PROTECTED]> wrote:
Another way of saying: factorial 0 = 1 is a "by definition" thing in
Mathematics and everybody then accepts it,
i.e., there is no logical basis for it.
Actually, there is a method to the madness. To quote MathWorld:
"The special case 0! is defined to have value 0!==1, consistent with
the combinatorial interpretation of there being exactly one way to
arrange zero objects (i.e., there is a single permutation of zero
elements, namely the empty set emptyset)."
That sounds entirely reasonable to me.
By logical basis I mean in the context of the general definition of
factorial,
and that is Factorial N = N! = N*(N-1)*...*1 .
Which reminds me, my iterative variation of the algorithm totally
dropped the ball on this one. D'oh! :)
Corrected (if a bit less elegant):
--------------BEGIN CODE -----------------------------------------------
int
factorial(int y)
{
if (!y)
{
return 1;
}
int multiplier, result = y;
for (multiplier = 2; multiplier < y; multiplier++)
{
result *= multiplier;
}
return result;
}
---------------- END CODE -----------------------------------------------
Tess
(who apologises for her previous 0 case missing lameness)
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html