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.

Here is source code of the C program to Calculate the value of nCr. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C program to Calculate the value of nCr`

`*/`

`#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, i;

if (z == 0)

`{`

return(f);

`}`

`else`

`{`

for (i = 1; i <= z; i++)

`{`

f = f * i;

`}`

`}`

return(f);

`}`

Output: $ cc pgm12.c $ a.out Enter the value for N and R 5 2 The value of ncr is: 10

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.