In this tutorial, we will see a new concept that is C Program to **Calculate Permutation and Combination**.

**Permutation:** It means an arrangement of the things. When we say arrangement then we consider the order of the things.

**The formula to calculate permutation:**

We calculate permutation formula, given as follow

Number of permutation of **‘n‘** different things taken **‘r’** at a time is given by,

** ^{n}p_{r} = n!/(n-r)!**

**Example:** Suppose we have to form the number of consisting of three digits using the digits 1, 2 3,4. To form this number the digits have to be arranged. The different number will get formed depending upon the order in which we arrange the digits.

**Combination:** It means selection of the things. The order of things is considered where word selection is not important.

**The formula to calculate Combination:**

We calculate combination by formula, given as follow

^{n}C_{r = }n! / (n-r)! . r!

**Example:** Suppose that we have to make a team of 11 out of the members 20.

This is an example of the combination because an order of the member will not result in a change in the team that is no matter. No matter in which order we choose and male a order of the team only making the team of 11 is important.

**The concept you need to know from c**

## C Program to Calculate Permutation and Combination

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <stdio.h> #include <conio.h> main() { int n , r, ncr( int , int); long npr( int , int); long double fact( int); printf(" Enter value of n & r \n"); scanf("%d %d",&n , &r); if( n>= r) { printf( " %dC%d is %d\n", n,r,ncr( n , r)); printf(" %dP%d is %ld", n,r,npr( n, r)); } else { printf("WRONG INPUT?? enter the correct input"); } } long double fact( int p) { long double facts = 1; int i; for ( i = 1; i<= p; i++) facts = facts * i; return( facts); } int ncr ( int n, int r) { return( fact( n) / (fact( r) * fact(n- r) ) ) ; } long npr( int n , int r) { return( fact( n) / fact( n- r)); } |

**Output :**

**Explanation**** :**

- Write main function.
- Declare variable.
- Take input n and r.
- Calculate permutation and combination.
- Print permutation and combination.

## Leave a Reply