changeset 742 | b5b5583a3a08 |
parent 702 | 39e21a33ffb0 |
child 790 | 31a9f89776a3 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/fun-tests/fact.fun Thu Jul 30 13:50:54 2020 +0100 @@ -0,0 +1,17 @@ +// a simple factorial program +// (including a tail recursive version) + + +def fact(n) = + if n == 0 then 1 else n * fact(n - 1); + +def facT(n, acc) = + if n == 0 then acc else facT(n - 1, n * acc); + +def facTi(n) = facT(n, 1); + +//fact(10) +//facTi(10) + +write(facTi(6)) +