calculate n choose k ( nck )


/* C program to calculate nck of a given number */
#include<stdio.h>
int fact(int);
int main()
{
         int n,k;
         printf("enter n, k: ");
         scanf("%d%d",&n,&k);
         if(n>=k)                               /* n sholud be greater than or equal to k */
        {
                  int result;
                  result=(fact(n)/(fact(k)*fact(n-k)));         /* recursive function call    */
                  printf("%d",result);
         }
         return 0;
}
int fact(int n)                      /* function for the factorial of a number  */
{
            if(n==0)                 /*    base case     */
           {
            return 1;
           }
           else
          {
                  int i,a=1;               /*    recursive case       */
                  for(i=n;i>0;i--)
                  a=a*i;
                  return a;                /* returning value   */
  }
}
Sample input and output:
enter n, k: 8 3
56