Factorial: Difference between revisions
Content added Content deleted
(Jakt) |
No edit summary |
||
Line 4,153: | Line 4,153: | ||
=> |
=> |
||
"265252859812191058636308480000000"</syntaxhighlight> |
"265252859812191058636308480000000"</syntaxhighlight> |
||
=={{header|EMal}}== |
|||
<syntaxhighlight lang="emal"> |
|||
fun iterative = int by int n |
|||
int result = 1 |
|||
for int i = 2; i <= n; ++i do result *= i end |
|||
return result |
|||
end |
|||
fun recursive = int by int n do return when(n <= 0, 1, n * recursive(n - 1)) end |
|||
writeLine("n".padStart(2, " ") + " " + "iterative".padStart(19, " ") + " " + "recursive".padStart(19, " ")) |
|||
for int n = 0; n < 21; ++n |
|||
write((text!n).padStart(2, " ")) |
|||
write(" " + (text!iterative(n)).padStart(19, " ")) |
|||
write(" " + (text!recursive(n)).padStart(19, " ")) |
|||
writeLine() |
|||
end |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
n iterative recursive |
|||
0 1 1 |
|||
1 1 1 |
|||
2 2 2 |
|||
3 6 6 |
|||
4 24 24 |
|||
5 120 120 |
|||
6 720 720 |
|||
7 5040 5040 |
|||
8 40320 40320 |
|||
9 362880 362880 |
|||
10 3628800 3628800 |
|||
11 39916800 39916800 |
|||
12 479001600 479001600 |
|||
13 6227020800 6227020800 |
|||
14 87178291200 87178291200 |
|||
15 1307674368000 1307674368000 |
|||
16 20922789888000 20922789888000 |
|||
17 355687428096000 355687428096000 |
|||
18 6402373705728000 6402373705728000 |
|||
19 121645100408832000 121645100408832000 |
|||
20 2432902008176640000 2432902008176640000 |
|||
</pre> |
|||
=={{header|embedded C for AVR MCU}}== |
=={{header|embedded C for AVR MCU}}== |