C program to calculate the value of nPr

nPr represents n permutation r and value of nPr is (n!) / (n-r)!.

`#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

Please refer Permutation Coefficient for efficient methods to compute nPr.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the **Essential Maths for CP Course** at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer **Complete Interview Preparation Course****.**