In this example, we are calculating the value of nPr based on the given values of n and r.
#include <stdio.h>
int fact(int);
void main()
{
int n, r, npr_var;
printf("Enter the value of n:");
scanf("%d", &n);
printf("\nEnter the value of r:");
scanf("%d", &r);
npr_var = fact(n) / fact(n - r);
printf("\nThe value of P(%d,%d) is: %d",n,r,npr_var);
}
int fact(int num)
{
int k = 1, i;
if (num == 0)
{
return(k);
}
else
{
for (i = 1; i <= num; i++)
{
k = k * i;
}
}
return(k);
}
Output :
Enter the value of n:5
Enter the value of r:2
The value of P(5,2) is: 20
Ask anything about this examples