PERMUTATION AND COMBINATION
C++ CODE :)
#include<iostream>
using namespace std;
long factorial(int A);
long find_ncr(int x, int y);
long find_npr(int t, int s);
int main()
{
int n, r;
long nCr, nPr;
cout<<"Enter n = ";
cin>>n;
cout<<"Enter r = ";
cin>>r;
nCr = find_ncr(n,r);
nPr = find_npr(n,r);
cout<<"1) Combination of "<<n<<" and "<<r<<" is = "<<nCr<<endl;
cout<<"2) Permutation of "<<n<<" and "<<r<<" is = "<<nPr<<endl;
return 0;
}
long find_ncr(int x, int y )
{
long result;
result=factorial(x)/factorial(x-y)*factorial(y);
return (result);
}
long find_npr(int t, int s)
{
long result1;
result1=factorial(t)/factorial(t-s);
return (result1);
}
long factorial(int A)
{
int i;
long r=1;
for( i=1;i<=A;i++ )
r=r*i;
return (r);
}
Input && Output :)
0 Comments