C program to find npr; Through this tutorial, we will learn how to find npr in c program.
In mathematics, nPr is the permutation of arrangement of ‘r’ objects from a set of ‘n’ objects, into an order or sequence. The formula to find permutation is: nPr = (n!) / (n-r)! Combination, nCr, is the selection of r objects from a set of n objects, such that order of objects does not matter.
C Program to Find nPr
// C Program To Calculate The Value on nPr #include <stdio.h> int fact(int n){ int i, a = 1; for (i = 1; i <= n; i++){ a = a * i; } return a; } int main(){ int n, r, npr; // Asking for Input printf("Enter the value of n: "); scanf("%d", &n); printf("Enter the value of p: "); scanf("%d", &r); npr = fact(n) / fact(n-r); printf("The Value of P(%d,%d) is %d.", n, r, npr); return 0; }
The output of the above c program; as follows:
Enter the value of n: 5 Enter the value of p: 3 The Value of P(5,3) is 60.