Java program to calculate the value of nCr
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
nCr: nCr is known as a combination, which is the method of selection of 'r' objects from a set of 'n' objects where the order of selection does not matter.
To find the value of nCr, we use the formula: nCr = n!/[r!( n-r)!]
Program/Source Code:
The source code to calculate the value of nCr is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contains two static methods getFactorial() and main().
The getFactorial() method is used to calculate the factorial of the given number.
The main() method is an entry point for the program. Here, we read values N, R from the user using the Scanner class. Then we calculated the nCr and printed the result.