C Program to find nCr

This program finds the NCR ( to calculate combinations). The program displays the output when the values of n and r are provided. We have also created a function called facto to find the factorial of a number.
The equation is nCr = n! / r! * (n - r)!


#include<stdio.h>
int facto(int f)
{
int fact = 1;
for(;f>0;f--)
{
fact=fact*f;
}
return fact;
}
int main()
{
int n,r;
float s;
printf("n == ");
scanf("%d",&n);
printf("r == ");
scanf("%d",&r);
s = facto(n)/(facto(n-r) * facto(r));
printf("%d C %d = %f ",n,r,s);
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub

Comments