C program to find ᵑCᵣ of a number

#include< stdio.h >
#include< conio.h >
void main()
{
          int n,r,ncr;
          int fact (int num);
          clrscr();
          printf("Enter the values of n and r:");
          scanf("\t%d\t %d",&n,&r);
          ncr=fact(n)/(fact(r)*fact(n-r));
          printf("nCr =%d",ncr);
          getch();
}
int fact (int num)
{
         int i,a=1;
         for(i=1;i<=num;i++)
        {
                    a=a*i;
        }
        return a;
}

OUTPUT :

Enter the values of n and r:3 2
nCr =3

No comments :

Post a Comment