- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C Program find nCr and nPr.

In C programming language, **nCr** is referred as the **combination**. nCr is the selection of r objects from a set of n objects, where the order of objects does not matter.

**nPr** is referred as the **permutation**. nPr is arrangement of 'r' objects from a set of 'n' objects, which should be in an order or sequence.

## Permutations and combinations formulas

The formulas to find the permutation and combination of given numbers in C language are given below −

- nCr = n!/(r!*(n-r)!)
- nPr = n!/(n-r)!.

The logic used to find nCr is as follows −

result = factorial(n)/(factorial(r)*factorial(n-r));

The logic used to find nPr is as follows −

result = factorial(n)/factorial(n-r);

## Example

Following is the C program to find the permutation and combination of given numbers −

#include <stdio.h> long factorial(int); long find_ncr(int, int); long find_npr(int, int); int main(){ int n, r; long ncr, npr; printf("Enter the value of n and r\n"); scanf("%d%d",&n,&r); ncr = find_ncr(n, r); npr = find_npr(n, r); printf("%dC%d = %ld\n", n, r, ncr); printf("%dP%d = %ld\n", n, r, npr); return 0; } long find_ncr(int n, int r) { long result; result = factorial(n)/(factorial(r)*factorial(n-r)); return result; } long find_npr(int n, int r) { long result; result = factorial(n)/factorial(n-r); return result; } long factorial(int n) { int c; long result = 1; for (c = 1; c <= n; c++) result = result*c; return result; }

## Output

When the above program is executed, it produces the following output −

Enter the value of n and r 5 2 5C2 = 10 5P2 = 20

- Related Questions & Answers
- C program to calculate the value of nPr?
- Program to calculate the value of nPr in C Program
- Program to calculate value of nCr in C++
- Java Program to Perform nCr (rcombinations)
- C++ Program to Compute Combinations using Recurrence Relation for nCr
- Find if nCr is divisible by the given prime in C++
- Find a pair from the given array with maximum nCr value in C++
- Program to find nCr values for r in range 0 to n, in an efficient way in Python
- C++ Program to Find Quotient and Remainder
- Find a pair from the given array with maximum nCr value in Python
- Write a C# program to find GCD and LCM?
- C++ Program to find and replace in a string
- C++ Program to Find Basis and Dimension of a Matrix
- C++ program to insert delete and find from set STL
- C program to find sum and difference of two numbers

Advertisements