Guest User

Untitled

a guest
Feb 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int fact(unsigned int n){
  5. if(n==0){
  6. return 1;
  7. }
  8. if(n==1){
  9. return 1;
  10. }
  11. return fact(n-1) * n;
  12. }
  13.  
  14. int combination(int n, int r){
  15. return (fact(n) / (fact(r) * fact(n-r) ) );
  16. }
  17.  
  18. int permutation(int n, int r){
  19. return (fact(n) / (fact(n-r)));
  20. }
  21.  
  22. int main(){
  23. int n, r;
  24. cout << "Enter the value of n = ";
  25. cin >> n;
  26. cout << "Enter the value of r = ";
  27. cin >> r;
  28. cout << "Combination = " << combination(n, r) << endl;
  29. cout << "Permutation = " << permutation(n, r) << endl;
  30. return 0;
  31. }
Add Comment
Please, Sign In to add comment