progs/fun-tests/fact.fun
changeset 742 b5b5583a3a08
parent 702 39e21a33ffb0
child 790 31a9f89776a3
equal deleted inserted replaced
741:e66bd5c563eb 742:b5b5583a3a08
       
     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