Anonymous user
Evaluate binomial coefficients: Difference between revisions
m
→{{header|REXX}}: added/changed comments, changed output, added whitespace, added subroutine fences. -- ~~~~
m (→{{header|REXX}}: added/changed comments, changed output, added whitespace, added subroutine fences. -- ~~~~) |
|||
Line 1,046:
=={{header|REXX}}==
The task is to compute ANY binomial coefficient(s), but this example is limited to 100k digits.
<lang rexx>/*REXX program calculates binomial coefficients (aka, combinations).
numeric digits 100000
parse arg n k .
say '
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────COMB subroutine─────────────────────*/
comb: procedure; parse arg x,y; return fact(x) / (fact(x-y) * fact(y))▼
/*──────────────────────────────────FACT subroutine─────────────────────*/
▲comb: procedure; parse arg x,y; return fact(x)/(fact(x-y)*fact(y))
fact: procedure; parse arg z; !=1; do j=2 to z; !=!*j; end; return !</lang>
<pre>
</pre>
▲<pre style="height:5ex;overflow:scroll">
▲comb(1200,120)=1004576581793084916475353119318331966507299414258370667602185866686463289093457468590558508056798211449853806741873396451735444387513582540860551330127062642417424083600
</pre>
|