You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
758 B
C++

#include < iostream.h >
long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);
main()
{
int n, r;
long ncr, npr;
cout<<"Enter the value of n and r\n";
cin>>n>>r;
ncr = find_ncr(n, r);
npr = find_npr(n, r);
cout<<n<<"C"<<r<<" ="<<ncr<<"\n";
cout<<n<<"P"<<r<<"=" <<npr<<"\n";
return 0;
}
long find_ncr(int n, int r)
{
long result;
result = factorial(n)/(factorial(r)*factorial(n-r));
return result;
}
long find_npr(int n, int r)
{
long result;
result = factorial(n)/factorial(n-r);
return result;
}
long factorial(int n)
{
int c;
long result = 1;
for( c = 1 ; c < = n ; c++ )
result = result*c;
return ( result );
}