Created
December 29, 2019 05:41
-
-
Save gsscoder/1df47123f19313110a7e8aba9c1b91e8 to your computer and use it in GitHub Desktop.
Scala program to calculate factorial of a number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ sbt | |
// sbt:factorial> ~run 10 | |
// [info] running sample.Sample 10 | |
// 3628800 | |
package sample | |
object Sample extends App { | |
println(factorial(args(0).toLong).toString) | |
def factorial (num: Long) : Long = { | |
if (num == 0) { | |
return 1 | |
} | |
return num * factorial(num - 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment