Skip to content

Instantly share code, notes, and snippets.

@codemilli
Created March 7, 2017 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemilli/7c37c1008020cfbc9a42cd6c04444469 to your computer and use it in GitHub Desktop.
Save codemilli/7c37c1008020cfbc9a42cd6c04444469 to your computer and use it in GitHub Desktop.
def factorial(number: Int) : Int = {
def factorialWithAccumulator(accumulator: Int, number: Int) : Int = {
if (number == 1)
return accumulator
else
factorialWithAccumulator(accumulator * number, number - 1)
}
factorialWithAccumulator(1, number)
}
println(factorial(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment