C Program to find Combinations nCr

Program

#include <stdio.h>
int fact(int n) {
  int i = 1;
  while (n != 0) {
    i = i * n;
    n--;
  }
  return i;
}
void main() {
  int n, r, ncr;
  printf("Enter value of n:\t");
  scanf("%d", &n);
  printf("Enter value of r:\t");
  scanf("%d", &r);
  ncr = fact(n) / (fact(r) * fact(n - r));
  printf("Combination:\t%d\n", ncr);
}

Output

Enter value of n:	9
Enter value of r:	4
Combination:	126