This C Program calculates the value of nPr. Here we need find all possible rearrangement of the element i.e all the possible permutation value. A permutation is a re-arrangement of elements of a set. Any duplications of the collected elements in different orders is allowed. A permutation therefore tends to be a large number.
Here is source code of the C program to calculate the Value of nPr. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to Calculate the Value of nPr
int n, r;
printf("Enter value for n and r\n");
scanf("%d%d", &n, &r);
int npr = fact(n) / fact(n - r);
printf("\n Permutation values is = %d", npr);
int fact(int x)
if (x <= 1)
return x * fact(x - 1);
Output: $ cc pgm13.c $ a.out 40320 Enter value for n and r 5 4 Permutation values is = 120
Sanfoundry Global Education & Learning Series – 1000 C Programs.
If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.
« Prev Page - C Program to Input a String & Store their Ascii Values in an Integer Array & Print the Array