Calculate nCr C Program

By | September 1, 2016

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)

Find Value of nCr in C Programming using Functions

Method 1: C Program To Calculate nCr using Function

#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

#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

C Program To Calculate nCr with Functions

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.

Recommended Programs
C Program For Addition of Complex Numbers
C Program To Calculate Simple Interest using Functions
C Program To Solve Trapezoidal Rule
C Program To Binary Value into Decimal Number
Solve Simpsons Rule in C Programming
C Program To Calculate Value of nPr
C Program To Solve Compound Interest using Functions

4 thoughts on “Calculate nCr C Program

  1. Mayur Vidhatr

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

    Reply
  2. Tushar Soni Post author

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

    Reply
  3. Virat Saxena

    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.

    Reply

Let's Discuss