Write a C program to find or calculate the nCr. This combination formula can also represent as C(n, r). The mathematical formula to calculate nCr is nCr = n!/( r!(n – r)!). This program allows entering the n and r value and calculates the nCr. Here, we created a function that returns the factorial of a given number.
#include <stdio.h>
int factorial(int Number)
{
if (Number == 0 || Number == 1)
return 1;
else
return Number * factorial (Number -1);
}
int main()
{
int n, r, ncrResult;
printf("Enter the Number = ");
scanf("%d",&n);
printf("Enter the r Value = ");
scanf("%d",&r);
ncrResult = factorial(n)/ (factorial(r) * factorial(n - r));
printf("The Final Result of nCr = %d\n", ncrResult);
return 0;
}
