Hello all, I'm very confused on this K factor stuff.....I understand that...12…*k indicates the product of consecutive numbers and therefore:

``````1*2*…*5
``````

is actually

``````1*2*3*4*5 = 120
``````

But I'm not sure how to write that as a code. I have the following information:

``````/* pseudocode for Binomial
Coefficients */
int binomial(int n, int k)
{
If (n < k) Then return (0)
Else
{
Set denominator = 1*2*...*k
Set numerator = (n-k+1)*(n-k+2)*...*(n-1)*n
return (numerator / denominator)
} // else
End if
}
``````

Does k represent 5 or just any number?? Is there some type of formula???

Edited by Nick Evan: Fixed formatting

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by confusedndazed

no. the k is passed in from main. So k can be any number.

For example, inside you main :

``````int main()
{
binomial(5, 10); // here k = 10;
binomial(3, 276); // here k is 276
}``````

no. the k is passed in from main. So k can be any number.

For example, inside you main :

``````int main()
{
binomial(5, 10); // here k = 10;
binomial(3, 276); // here k is 276
}``````

OK thx!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.