75
Program to print the combination (nCr) of the given number
Combination (nCr) can be defined as the combination of n things taken r at a time without any repetition.
ncr can be calculated as,
Algorithm
MAIN
- STEP 1: START
- STEP 2: DEFINE n, r
- STEP 3: ENTER n, r
- STEP 4: PRINT nCr(n, r)
- STEP 5: END
nCr(n r)
- STEP 1: START
- STEP 2: RETURN fact(n) / (fact(r)*fact (n-r))
- STEP 3: END
fact(n)
- STEP 1: START
- STEP 2: SET res= 1
- STEP 3: REPEAT STEP 3 and STEP 4 UNTIL i<=n
- STEP 4: res = res*i
- STEP 5: RETURN res
- STEP 6: END
Java Program
Output:
Enter the value of n and r? 6 4 nCr = 15
C Program
Output:
Enter the value of n and r? 5 3 nCr = 10
Python Program
Output:
Enter the value of n 5 Enter the value of r 3 nCr = 10
C# Program
Output:
Enter the value of n and r? 5 3 nCr = 10
PHP Program
Output:
Enter the value of n and r? 5 3 nCr = 10
Next Topic#