C program to calculate the value of nPr Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report nPr represents n permutation r and value of nPr is (n!) / (n-r)!. C #include<stdio.h> int fact(int n) { if (n <= 1) return 1; return n*fact(n-1); } int nPr(int n, int r) { return fact(n)/fact(n-r); } int main() { int n, r; printf("Enter n: "); scanf("%d", &n); printf("Enter r: "); scanf("%d", &r); printf("%dP%d is %d", n, r, nPr(n, r)); return 0; } Enter n: 5 Enter r: 2 5P2 is 20 Time Complexity: O(n) Auxiliary Space: O(n) Please refer Permutation Coefficient for efficient methods to compute nPr. C Program to Calculate the nPr Comment More infoAdvertise with us Next Article Program to find the count of coins of each type from the given ratio K kartik Follow Improve Article Tags : Mathematical Combinatorial DSA factorial Practice Tags : CombinatorialfactorialMathematical Similar Reads Program to find the Depreciation of Value The value of any article or item subject to wear and tear, decreases with time. This decrease is called its Depreciation. Given three variable V1, R and T where V1 is the initial value, R is the rate of depreciation and T is the time in years. The task is to find the value of the item after T years. 3 min read Program to find the count of coins of each type from the given ratio Given the total number of Rupees in a bag and the ratio of coins. The bag contains only 1 Rs, 50 paise, 25 paise coins in X, Y, Z, ratio. The task is to determine the number of 1 Rs coins, 50 Paise coins, and 25 paise coins So that after summation of all these we again get the total rupees given.Exa 6 min read Class 9 RD Sharma Solutions - Chapter 19 Surface Area And Volume of a Right Circular Cylinder - Exercise 19.2 | Set 1 This geometric figure is known as Right Circular Cylinder, which has ample usages in day to day real life situation arises in Engineering, Architecture and Manufacture. It is well used in areas of estimations concerning materials as well as design works concerning the physical structure of an object 13 min read Program to calculate the value of nPr 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.nPr = n! / (n - r)! Examples:Input: n = 5 r = 2Output: 20Explanation: 5P 4 min read Program to find the profit or loss when CP of N items is equal to SP of M items Given N and M denoting that the Cost Price of N articles is equal to the Selling Price of M articles. The task is to determine the profit or Loss percentage. Examples: Input: N = 8, M = 9 Output: Loss = -11.11% Input: N = 8, M = 5 Output: Profit = 60% Formula:- Below is the implementation of the abo 4 min read Maximum litres of water that can be bought with N Rupees Given N Rupees. A liter plastic bottle of water costs A Rupees and a litre of glass bottle of water costs B Rupees. But the empty glass bottle after buying can be exchanged for C Rupees. Find the maximum liters of water which can be bought with N Rupees. Examples: Input: N = 10 , A = 11 , B = 9 , C 5 min read Like