193030

Combinations recursive

May 8th, 2021
1,187
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Combinations
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int nCR(int n, int r){
  8.     if (r == 0 || r == n){
  9.         return 1; //terminate
  10.     }
  11.     else{
  12.         return nCR(n-1, r-1) + nCR(n-1, r); //recursive calls
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.     int res = nCR(3,2);
  19.  cout << res << endl;
  20. }
  21.  
RAW Paste Data