On 11/28/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
I thought by definition y! = y * (y-1) * (y-2) * ... * 1so 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.
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
