C Programming Code Examples C > Mathematics Code Examples C program to Calculate the value of nCr C program to Calculate the value of nCr This C Program Calculates the value of nCr. The algorithm used in this program is nCr = n! /((n-r)!r!). Here we need to find all the possible combination of the value n and r. A combination is one or more elements selected from a set without regard to the order. The "without regard" means that the collection matters rather than order in combinations, so in the above example, the fact we ABC, ACB, BAC, BCA, CAB, CBA... for combinations, these are all 1 combinationof letters A, B and C. #include <stdio.h> int fact(int z); void main() { int n, r, ncr; printf("\n Enter the value for N and R \n"); scanf("%d%d", &n, &r); ncr = fact(n) / (fact(r) * fact(n - r)); printf("\n The value of ncr is: %d", ncr); } int fact(int z) { int f = 1, j; if (z == 0) { return(f); } else { for (j = 1; j <= z; j++) { f = f * j; } } return(f); }