epfl-archive/cs320-clp/examples/Factorial.scala

13 lines
253 B
Scala
Raw Normal View History

2022-04-07 18:43:21 +02:00
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)))
}