## C Program To Calculate nCr Value

Learn How To Calculate nCr in C Programming Language. This C Program makes use of the **Factorial Function in C Programming **to find the Value of nCr. nCr is also commonly written as **C(n/r)**.

This C Code to Find Value of nCr finds the total Number of different Combinations of **n** Distinct Objects taken **r** at a time. An important part of finding combination in C Programming is calculation of the Factorial of a Number.

#### Mathematical Formula To Find Combination C(n, r)

#### Method 1: C Program To Calculate nCr using Function

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<stdio.h> int Factorial(int x) { int factorial = 1, count; for(count = x; count > 1; count--) { factorial = factorial * count; } return factorial; } int main() { int n, r; float result; printf("Enter value of N:\t"); scanf("%d", &n); printf("Enter value of R:\t"); scanf("%d", &r); result = (float)Factorial(n) / (Factorial(r) * Factorial(n - r)); printf("\nValue of nCr:\t %.2f\n", result); return 0; } |

#### Method 2: C Program To Find Value of nCr using While Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<stdio.h> int Factorial(int x) { int factorial = 1, count = x; while(count > 1) { factorial = factorial * count; count--; }; return factorial; } int main() { int n, r; float result; printf("Enter value of N:\t"); scanf("%d", &n); printf("Enter value of R:\t"); scanf("%d", &r); result = (float)Factorial(n) / (Factorial(r) * Factorial(n - r)); printf("\nValue of nCr:\t %.2f\n", result); return 0; } |

#### Output

If you have any compilation error or doubts in this C Program To Compute nCr with and without Functions, let us know about it in the Comment Section below.

Can we solve this C Program for finding value of C(n/r) using Recursive approach?

Yes. You can definitely. You should have a look at Factorial Program using Recursion on the website under C Programs Menu Bar.

Perfect ncr program in c code. Thanks.

The different groups that can be formed out of a given number of things taken some or all of them at a time is called combination.