C Code 32 _ To Find p or r Values in nPr Permutation Problem
permutations:
Formula to find p is
p(n,r) = n! / (n-r)!
Program:
#include<stdio.h>
int main()
{
int
n=0,r=0,p=0,i,ch,u=1,l=1;;
printf("*
* * * * nPr Problems on Permutations * * * * *");
printf("\n\n1
- To find p\n\n2 - To find r\n\nEnter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n\nEnter the n value : ");
scanf("%d",&n);
printf("\n\nEnter
the p value : ");
scanf("%d",&p);
i=n;
while(p>1)
{
p=p/i;
i=i-1;
r=r+1;
}
printf("\n\nThe
value of r is : %d",r);
break;
case 2:
printf("\n\nEnter the n value : ");
scanf("%d",&n);
printf("\n\nEnter
the r value : ");
scanf("%d",&r);
for(i=n;i>=1;i--)
{
u=u*i;
}
for(i=n-r;i>=1;i--)
{
l=l*i;
}
p=u/l;
printf("\n\nThe
value of p is %d",p);
break;
default:
printf("\n\nEnter
either 1 or 2 only");
}
return
0;
}
Output:
Thank You ...
For java codes visit : https://iamafutureprogrammer.blogspot.com/p/java-codes.html
To know How Internet works visit : https://iamafutureprogrammer.blogspot.com/p/how-internet-works.html
0 comments: