Created
September 6, 2011 18:56
-
-
Save cgopalan/1198617 to your computer and use it in GitHub Desktop.
Scala Tail Recursive Factorial
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
object TailRecursiveFactorial { | |
def factorial(n: Int, product: Int): Int = | |
if (n == 1) product else factorial(n - 1, n * product) | |
def main(args: Array[String]) { | |
println("Factorial of 8 is: " + factorial(8,1)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment