Factorial: Difference between revisions

Content added Content deleted
(Add entry for Beads language)
m (changed beads category index)
Line 1,216: Line 1,216:
END IF
END IF
END FUNCTION</lang>
END FUNCTION</lang>


=={{header|Beads}}==
<lang Beads>beads 1 program Factorial
// only works for cardinal numbers 0..N
calc main_init
log to_str(Iterative(4)) // 24
log to_str(Recursive(5)) // 120

calc Iterative(
n:num -- number of iterations
):num -- result
var total = 1
loop from:2 to:n index:ix
total = ix * total
return total
calc Recursive ditto
if n <= 1
return 1
else
return n * Recursive(n-1)
</lang>
{{out}}
<pre>24
120</pre>


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
Line 1,414: Line 1,388:
f(1000)
f(1000)
quit</lang>
quit</lang>

=={{header|Beads}}==
<lang Beads>beads 1 program Factorial
// only works for cardinal numbers 0..N
calc main_init
log to_str(Iterative(4)) // 24
log to_str(Recursive(5)) // 120

calc Iterative(
n:num -- number of iterations
):num -- result
var total = 1
loop from:2 to:n index:ix
total = ix * total
return total
calc Recursive ditto
if n <= 1
return 1
else
return n * Recursive(n-1)
</lang>
{{out}}
<pre>24
120</pre>


=={{header|beeswax}}==
=={{header|beeswax}}==