Multifactorial: Difference between revisions

Updated to work with Nim 1.4: added missing parameter types, added missing '\n'.
(Added Quackery.)
(Updated to work with Nim 1.4: added missing parameter types, added missing '\n'.)
Line 1,296:
=={{header|Nim}}==
<lang nim># Recursive
proc multifact(n, deg: int): int =
result = (if n <= deg: n else: n * multifact(n - deg, deg))
 
# Iterative
proc multifactI(n, deg: int): int =
result = n
var n = n
Line 1,306:
result *= n - deg
n -= deg
 
for i in 1..5:
stdout.write "\nDegreeDegree ", i, ": "
for j in 1..10:
stdout.write multifactI(j, i), " "</lang>
stdout.write('\n')</lang>
Output:
 
{{out}}
<pre>Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800
Degree 2: 1 2 3 8 15 48 105 384 945 3840
Anonymous user