Program 178:
Formula for permutation us nCr=n!/r!(n-r)! under condition of n>=r,n>=0,r>=0
This is same as nPr Program except the formula where r! is used.
Output:
#include<stdio.h>
int factorial(int);
main()
{
int n,r;
float nCr;
printf("Enter value of n in nPr\n");
scanf("%d",&n);
printf("Enter value of r in nPr\n");
scanf("%d",&r);
if(n>=r&&n>=0&&r>=0)
{
nCr=(float)factorial(n)/(factorial(r)*factorial(n-r));
printf("Value of %dC%d=%f\n",n,r,nCr);
}
else
{
printf("Invalid Entry\n");
}
}
int factorial(int num)
{
int i,fact=1;
for(i=1;i<=num;i++)
{
fact=fact*i;
}
return(fact);
}
Explanation:Formula for permutation us nCr=n!/r!(n-r)! under condition of n>=r,n>=0,r>=0
This is same as nPr Program except the formula where r! is used.
- To understand factorial in detail CLICK HERE.
Output:


