Javatpoint Logo
Javatpoint Logo

Program to print the permutation (nPr) of the given number

Permutation

It is an ordered-arrangement/combination of a set of things or collection of objects.

For example, we have a set of letters A, B, and C.....describing permutations as n distinct objects taken r at a time.

Permutation of a list of n elements:

Algorithm

  • STEP 1: START
  • STEP 2: DEFINE n, r, per, fact1, fact2
  • STEP 3: PRINT n, r
  • STEP 4: fact1 =n
  • STEP 5: REPEAT STEP 6 UNTIL i>=1
  • STEP 6: fact1 = fact1*i
  • STEP 7: DEFINE number
  • STEP 8: SET number = n - r
  • STEP 9: fact 2 = fact2*i
  • STEP 10: SET per = fact1/fact2
  • STEP 11: PRINT per
  • STEP 12: END

Java Program

Output:

Enter the Value of n and r?
5
2
nPr = 20

C program

Output:

Enter the Value of n and r?
5
2
nPr = 20

C# Program

Output:

Enter the Value of n and r?
5
2
nPr = 20

Python Program

Output:

Enter the value of n:
5
Enter the value of r:
2
nPr = 20
Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA