Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
added calculateThePermutationOfNObjectsTakenRAtATime in scala (#5577)
Browse files Browse the repository at this point in the history
* checkArmstrongNumber in Scala

* CombinationCalculator in Scala

* CombinationCalculator in Scala deleted

* calculateTheCombinationOfNObjectsTakenRAtATime in Scala added

---------

Co-authored-by: Harsh Raj <harshraj8843@gmail.com>
  • Loading branch information
Adelechka and harshraj8843 authored Mar 28, 2024
1 parent 3ed4755 commit df063d2
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scala.io.StdIn.readInt

object calculateTheCombinationOfNObjectsTakenRAtATime {
def main(args: Array[String]): Unit = {
val n = readInt()
val r = readInt()
println(combination(n, r))
}

def factorial(n: Int): BigInt = {
if (n == 0) 1
else n * factorial(n - 1)
}

def combination(n: Int, r: Int): BigInt = {
factorial(n) / (factorial(r) * factorial(n - r))
}
}

0 comments on commit df063d2

Please sign in to comment.