How to Calculate the Value of nPr
Use the following permutation formula to calculate the value of nPr:
Where:
Problem Statement
You’re given the values of n and r. You need to calculate the value of nPr.
Example 1: Let n = 10 and r = 5.
Therefore, nPr = 10! / (10-5)! = 10! / 5! = 30240.
Thus, the output is 30240.
Example 2: Let n = 3 and r = 2.
Therefore, nPr = 3! / (3-2)! = 3! / 1! = 6.
Thus, the output is 6.
Example 3: Let n = 8 and r = 0.
Therefore, nPr = 8! / (8-0)! = 8! / 8! = 1.
Thus, the output is 1.
C++ Program to Calculate the Value of nPr
Below is the C++ program to calculate the value of nPr:
Output:
Python Program to Calculate the Value of nPr
Below is the Python program to calculate the value of nPr:
Output:
JavaScript Program to Calculate the Value of nPr
Below is the JavaScript program to calculate the value of nPr:
Output:
C Program to Calculate the Value of nPr
Below is the C program to calculate the value of nPr:
Output:
Java Program to Calculate the Value of nPr
Below is the Java program to calculate the value of nPr:
Output:
Does Programming Affect Your Brain?
Just like artistry, programming also affects your brain in certain ways. Scientists studied programmer’s brains and found that programming helps to strengthen brain health. You’ll be amazed to know what science says about how programming can affect your brain.