/* Program to generate Permutation (nPr) */
/* Here we will be generating the Permutation. We are taking the the n and r as a input from the user and will generate the desire output. */
/* Program to calculate Permutation nPr */
//Header File
#include<iostream.h>
int fact(int);
int main()
{
int a,b,n,r;
cout<<"\n Enter the value of n : ";
cout<<"\n Enter the value of r : ";
cin>>r;
a=fact(n);
b=fact(n-r);
cout<<"\n Value of permutation : "<<a/b;
return 0;
}
int fact(int a)
{
int sum=1,i;
if(a==0)
return 1;
else
{
for(i=1;i<=a;i++)
{
sum=sum*i;
}
return sum;
}
}
0 comments:
Post a Comment