Evaluate binomial coefficients: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 5: | Line 5: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
<lang cpp> |
<lang cpp>double Factorial(double nValue) |
||
double Factorial(double nValue) |
|||
{ |
{ |
||
double result = nValue; |
double result = nValue; |
||
Line 29: | Line 27: | ||
nValue = result; |
nValue = result; |
||
return nValue; |
return nValue; |
||
} |
}</lang> |
||
</lang> |
Revision as of 19:37, 11 April 2010
Evaluate binomial coefficients
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
This programming task, is to calculate ANY binomial coefficient.
This formula is recommended: n!/k!(n-k)!
C++
<lang cpp>double Factorial(double nValue)
{ double result = nValue; double result_next; double pc = nValue; do { result_next = result*(pc-1); result = result_next; pc--; }while(pc>2); nValue = result; return nValue; }
double EvaluateBinomialCoefficient(double nValue)
{ double result;
result = (Factorial(m_nValue))/(Factorial(nValue)*Factorial((m_nValue - nValue))); nValue = result; return nValue; }</lang>