Factorial: Difference between revisions
Content added Content deleted
Line 9,574: | Line 9,574: | ||
3628800 3628800 3628800 |
3628800 3628800 3628800 |
||
39916800 39916800 39916800</pre> |
39916800 39916800 39916800</pre> |
||
=={{header|Soda}}== |
|||
===Recursive=== |
|||
<syntaxhighlight lang="soda"> |
|||
factorial (n : Int) : Int = |
|||
if n < 2 |
|||
then 1 |
|||
else n * factorial (n - 1) |
|||
</syntaxhighlight> |
|||
===Tail recursive=== |
|||
<syntaxhighlight lang="soda"> |
|||
@tailrec |
|||
_tailrec_fact (n : Int) (accum : Int) : Int = |
|||
if n < 2 |
|||
then accum |
|||
else _tailrec_fact (n - 1) (n * accum) |
|||
factorial (n : Int) : Int = |
|||
_tailrec_fact (n) (1) |
|||
</syntaxhighlight> |
|||
=={{header|SparForte}}== |
=={{header|SparForte}}== |