#include <iostream.h>
void main()
{
int i , n , r , P , C ;
int factorial , temp , result ;
cout<<"Enter a number,n and r :\n";
cin>>n>>r;
for (i=1,factorial=1 ; i<=n ; i++) /* Calculate n! */
factorial = factorial * i ;
for (i=1,temp=1 ; i<=r ; i++) /* Calculate r! */
temp = temp * i ;
for (i=1,result=1 ; i<=(n-r) ; i++) /* Calculate (n-r)!*/
result = result * i ;
P = factorial / temp ;
C = P / result ;
cout<<"Permutation : "<<P;
cout<<"Combination : "<<C;
}
0 comments:
Post a Comment