| changeset 742 | 155426396b5f |
| parent 702 | 67ab7162a861 |
| child 790 | 71ef7d9ef635 |
| 741:6512884e03b4 | 742:155426396b5f |
|---|---|
1 // a simple factorial program |
|
2 // (including a tail recursive version) |
|
3 |
|
4 |
|
5 def fact(n) = |
|
6 if n == 0 then 1 else n * fact(n - 1); |
|
7 |
|
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); |
|
12 |
|
13 //fact(10) |
|
14 //facTi(10) |
|
15 |
|
16 write(facTi(6)) |
|
17 |