Factorial in Scala
Example for versions
Scala 2.7.7-final
This example uses iterative factorial definition.
object Factorial {
def main(args: Array[String]) {
var f = BigInt(1)
format("0! = %s\n", f)
for {i <- 1 to 16} {
f *= i;
format("%s! = %s\n", i, f)
}
}
}
Comments
]]>blog comments powered by Disqus
]]>