The nPr termed as permutation. They are useful in finding possible permutation of the number in the sets of numbers. To calculate combinations, we will use the formulanPr = n! / (n – r)! , where n represents the total number of items, and r represents the number of items being chosen at a time.
#include <stdio.h>
int fact(int n)
{
int i;
int res = 1;
for (i = 2; i <= n; i++)
{
res = res * i;
}
return res;
}
int getnPr(int n, int r)
{
return fact(n)/fact(n-r);
}
int main()
{
int num, r;
long nprValue;
printf("Enter the value of num = ");
scanf("%d",&num);
printf("Enter the value of r = ");
scanf("%d",&r);
nprValue = getnPr(num, r);
printf("%d C %d = %ld\n", num, r, nprValue);
return 0;
}
Output:
Enter the value of num = 10 Enter the value of r = 4 10 P 4 = 5040
Output:
Enter the value of num = 10
need an explanation for this answer? contact us directly to get an explanation for this answerEnter the value of r = 4
10 P 4 = 5040