Contact Learn C
Copy Program Share Program

Program 178:To Calculate Combination value nCr

Program 178:
 
#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.

  1. To understand factorial in detail CLICK HERE.

Output:

Calculate Combination value nCr




 

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide