Daniel Bush wrote:
On 11/28/05, [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>*
<[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:
I thought by definition y! = y * (y-1) * (y-2) * ... * 1
so the function should be:
int factorial(int y)
{
if ( y =1){
return 1;
}
else
{
return (y * factorial(y - 1));
}
}
yiz
I think you mean y==1 not y=1. I love getting that wrong. I've had
hours of fun with that type of error (in javascript).
IIRC, 0! = 1. There's a reason for it somewhere. This is satsified
by the original function definition.
I think you might get infinite recursion if you try factorial(0) for a
version using y==1.
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.
O Plameras
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html