- Related Questions & Answers
- Program to calculate Bitonicity of an Array
- Program to calculate the area of a Tetrahedron
- C++ Program for BogoSort or Permutation Sort?
- A permutation where each element indicates either number of elements before or after it?
- Get the difference between dates and calculate salary with MySQL?
- How to calculate the difference between time in different MySQL columns?
- Program to calculate Area Of Octagon
- Program to calculate area of Enneagon
- Program to calculate area of Circumcircle of an Equilateral Triangle
- Program to calculate the area of an Circle inscribed in a Square
- Program to calculate area and volume of a Tetrahedron
- Program to calculate area and perimeter of Trapezium
- Program to calculate area and perimeter of equilateral triangle
- How to calculate timestamp difference in hours with MongoDB?
- Calculate the average value in a MongoDB document grouping by null?

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

Combination and permutation are a part of Combinatorics. Permutation is the different arrangements that a set of elements can make if the elements are taken one at a time, some at a time or all at a time. Combination is is the different ways of selecting elements if the elements are taken one at a time, some at a time or all at a time.

Number of permutations when there are total n elements and r elements need to be arranged.

Number of combinations when there are total n elements and r elements need to be selected.

A program that calculates combination and permutation in C++ is given as follows.

#include <iostream> using namespace std; int fact(int n) { if (n == 0 || n == 1) return 1; else return n * fact(n - 1); } int main() { int n, r, comb, per; cout<<"Enter n : "; cin>>n; cout<<"\nEnter r : "; cin>>r; comb = fact(n) / (fact(r) * fact(n-r)); cout << "\nCombination : " << comb; per = fact(n) / fact(n-r); cout << "\nPermutation : " << per; return 0; }

The output of the above program is as follows.

Enter n : 5 Enter r : 3 Combination : 10 Permutation : 60

Advertisements