author | Christian Urban <urbanc@in.tum.de> |
Thu, 14 Nov 2019 13:17:02 +0000 | |
changeset 687 | 8865f4f2be59 |
parent 655 | 3d04ee04966d |
child 702 | 39e21a33ffb0 |
permissions | -rw-r--r-- |
655 | 1 |
// a simple factorial program |
2 |
// (including a tail recursive version) |
|
224
70198792c2aa
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
|
655 | 4 |
|
5 |
def fact(n) = |
|
6 |
if n == 0 then 1 else n * fact(n - 1); |
|
224
70198792c2aa
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
|
655 | 8 |
def facT(n, acc) = |
9 |
if n == 0 then acc else facT(n - 1, n * acc); |
|
10 |
||
11 |
def facTi(n) = facT(n, 1); |
|
224
70198792c2aa
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
|
655 | 13 |
//fact(10) |
14 |
//facTi(10) |
|
224
70198792c2aa
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
|
655 | 16 |
write(facTi(5 + 5)) |
17 |