Skip to content

Instantly share code, notes, and snippets.

@cgopalan
Created September 6, 2011 18:56
Show Gist options
  • Save cgopalan/1198617 to your computer and use it in GitHub Desktop.
Save cgopalan/1198617 to your computer and use it in GitHub Desktop.
Scala Tail Recursive Factorial
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