## Find nCr and nPr using C program

We can find nCr and nPr using C program. Here we have given the C program to find the nCr and nPr. Before going ahead we should know what is nCr and nPr. nCr is used for determine the combination where nPr used for determine the Permutation. ## C program to find nCr and nPr

``````// C program to find nCr and nPr
#include <stdio.h>
long findFact(int);
long findNcr(int, int);
long findNpr(int, int);

int main(){
int r, n;
long npr, ncr;

printf("Enter the value of n : ");
scanf("%d",&n);
printf("Enter the value of r : ");
scanf("%d",&r);

ncr = findNcr(n, r);
npr = findNpr(n, r);

printf("\n%dC%d is = %ld\n", n, r, ncr);
printf("%dP%d is = %ld\n", n, r, npr);
return 0;
}

long findNcr(int n, int r){
long result;

result = findFact(n) / (findFact(r) * findFact(n - r));
return result;
}

long findNpr(int n, int r){
long result;

result = findFact(n) / findFact(n - r);
return result;
}

long findFact(int n) {
int i;
long result = 1;

for (i = 1; i <= n; i++){
result = result * i;
}
return result;
}``````

### Output of nCr and nPr program:

``````Enter the value of n : 15
Enter the value of r : 5

15C5 is = 4
15P5 is = 552``````

Previous pageHCF and LCM by C

Next pagePattern printing in C