epfl-archive/cs320-clp/examples/Factorial.scala
2022-04-07 18:43:21 +02:00

13 lines
253 B
Scala

object Factorial {
def fact(i: Int): Int = {
if (i < 2) { 1 }
else {
val rec: Int = fact(i-1);
i * rec
}
}
Std.printString("5! = " ++ Std.intToString(fact(5)));
Std.printString("10! = " ++ Std.intToString(fact(10)))
}