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 'combcombinations('n","k') =' comb(n,k)
exit /*stick a fork in it, we're done.*/
exit
 
/*──────────────────────────────────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>
Output '''output''' when using the input of: <tt> 5 3 </tt>
<pre>5 3</pre>
<pre>
combcombinations(5,3) = 10
</pre>
Output '''output''' when using the input of: <tt> 1200 120 </tt>
<pre style="height:5ex;overflow:scroll">
<pre>1200 120</pre>
combcombinations(1200,120) = 1004576581793084916475353119318331966507299414258370667602185866686463289093457468590558508056798211449853806741873396451735444387513582540860551330127062642417424083600
<pre style="height:5ex;overflow:scroll">
comb(1200,120)=1004576581793084916475353119318331966507299414258370667602185866686463289093457468590558508056798211449853806741873396451735444387513582540860551330127062642417424083600
</pre>