# C Program to find nPr and nCr

This is the C Program to find nCr and nPr given n and r

nPr(n, r) The number of possibilities for choosing an ordered set of r objects (a permutation) from a total of n objects.

Definition: nPr(n,r) = n! / (n-r)!

nCr(n, r) The number of different, unordered combinations of r objects from a set of n objects.

Definition: nCr(n,r) = nPr(n,r) / r!

```
#include<stdio.h>
main()
{
int n,r;
int ncr,npr;
printf("Enter the Values for n and r");
scanf("%d%d",&n,&r);
ncr=fncr(n,r);
npr=fnpr(n,r);
printf("%dC%d=%dn",n,r,ncr);
printf("%dP%d=%dn",n,r,npr);
}
int fncr(int n,int r)
{
int res;
res=fact(n)/(fact(r)*fact(n-r));
return res;
}
int fnpr(int n,int r)
{
int res;
res=fact(n)/fact(n-r);
return res;
}
int fact(int n)
{
int i;
int fact=1;
for(i=0;i<=n;i++)
{
fact=fact*n;
return fact;
}
}
```

## Recent Comments