Originally Posted by
DavT
Looking through your original code there are three errors that stand out:
Code:
/* should be */
for(i = 0; (r-i) >= 1; i++)
{
output = (output * (( n - i) / (r - i)));
return output;
}
Also, I agree with quzah that you should really only have one return in the function,
its a style thing but good consistent style tends to prevent errors.
HTH
You still have the same problem they do. Walk through that loop, and you'll find there is no need for a loop at all the way you have it:
Code:
/* three lines */
for(i = 0; (r-i) >= 1; i++)
{
output = (output * (( n - i) / (r - i)));
return always right now no matter what the loop says
}
You may as well just write:
Code:
/* two lines */
output = output * ((n - 0) / (r - 0));
return output;
Which can be simplified even more to just:
Code:
/* a single line */
return output * ( n / r );
Which is not what you want. That as my point.
Quzah.
[edit]/* comments added for clarification of my point */[/edit]