Evaluate binomial coefficients: Difference between revisions

Content added Content deleted
m (→‎{{header|TI-83 BASIC}}: Superfluous blanks suppressed)
Line 485: Line 485:
(100 98) = 50
(100 98) = 50
(100 50) = 1976664223067613962806675336</pre>
(100 50) = 1976664223067613962806675336</pre>

The above wouldn't work for me (100C50 correctly gives 100891344545564193334812497256). This next one is a translation of C#:
<lang d>T BinomialCoeff(T)(in T n, in T k)
{
T nn = n, kk = k, c = cast(T)1;

if (kk > nn - kk) kk = nn - kk;

for (T i = cast(T)0; i < kk; i++)
{
c = c * (nn - i);
c = c / (i + cast(T)1);
}

return c;
}

void main()
{
import std.stdio, std.bigint;

BinomialCoeff(10UL, 3UL).writeln;
BinomialCoeff(100.BigInt, 50.BigInt).writeln;
}</lang>
{{out}}
<pre>120
100891344545564193334812497256</pre>


=={{header|dc}}==
=={{header|dc}}==