Factorial: Difference between revisions

Added Odin variant
(Adds slope example)
(Added Odin variant)
Line 6,435:
<pre>30414093201713378043612608166064768844377641568960512000000000000 </pre>
In fact, all results given by Octave are precise up to their 16th digit, the rest seems to be "random" in all cases. Apparently, this is a consequence of Octave not being capable of arbitrary precision operation.
 
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
 
factorial :: proc(n: int) -> int {
return 1 if n == 0 else n * factorial(n - 1)
}
 
factorial_iterative :: proc(n: int) -> int {
result := 1
for i in 2..=n do result *= i
return result
}
 
main :: proc() {
assert(factorial(4) == 24)
assert(factorial_iterative(4) == 24)
}</syntaxhighlight>
 
=={{header|Oforth}}==
29

edits