Combination (nCr) can be defined as the combination of n things taken r at a time without any repetition.
ncr can be calculated as,
nCr = [n(n-1) ... (n-r+1)] / r(r-1)...1
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:
C Program
Output:
Python Program
Output:
C# Program
Output:
PHP Program
Output: