VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-calculate-the-value-of-npr/

⇱ Program to calculate the value of nPr - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to calculate the value of nPr

Last Updated : 2 Mar, 2026

Given two numbers, n and r, the task is to compute nPr, which represents the number of ways to arrange r elements from a set of n elements. It is calculated using the formula n!/(nāˆ’r)!, where "!" denotes the factorial operation.

šŸ‘ Permutation - Formula, Definition ...

Examples:

Input: n = 5
r = 2
Output: 20
Explanation:5P2 = 5! / (5 - 2)! = 20

Input: n = 6
r = 3
Output: 120
Explanation:6P3 = 6! / (6 - 3)! = 12

For calculating nPr using an iterative factorial function. First computes n! and (n - r)! separately and then divides them to get the result. The factorial function uses a loop to multiply numbers from 1 to n.


Output
5P2 = 20
Comment