Factorial: Difference between revisions
added SuperCollider factorial
WillBAnders (talk | contribs) (Add Rhovas solution (iterative & recursive)) |
(added SuperCollider factorial) |
||
Line 9,174:
printf("%f\n",fact2(8))
printf("%f\n",factorial(8))</syntaxhighlight>
=={{header|SuperCollider}}==
===Iterative===
<syntaxhighlight lang="SuperCollider">
f = { |n| (1..n).product };
f.(10);
// for numbers larger than 12, use 64 bit float
// instead of 32 bit integers, because the integer range is exceeded
// (1..n) returns an array of floats when n is a float
f.(20.0);
</syntaxhighlight>
===Recursive===
<syntaxhighlight lang="SuperCollider">
f = { |n| if(n < 2) { 1 } { n * f.(n - 1) } };
f.(10);
</syntaxhighlight>
=={{header|Swift}}==
|