Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Created May 7, 2017 04:15
Show Gist options
  • Save dgadiraju/9b85c8def853e1c567e74fd99080b22a to your computer and use it in GitHub Desktop.
Save dgadiraju/9b85c8def853e1c567e74fd99080b22a to your computer and use it in GitHub Desktop.
def fact(i: Int) = {
var res = 1
for(e <- i to 1 by -1)
res = res * e
res
}
def nCr(n: Int, r: Int) = {
fact(n)/(fact(n-r) * fact(r))
}
//Nested functions
def nCr(n: Int, r: Int) = {
def fact(i: Int) = {
var res = 1
for(e <- i to 1 by -1)
res = res * e
res
}
fact(n)/(fact(n-r) * fact(r))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment