fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include<iostream>
  9. #include <vector>
  10. using namespace std;
  11. void printSubsets(vector<int>&arr,vector<int>&ans,int i){
  12. if(i==arr.size()){
  13. for(int val:ans){
  14. cout<<val<<" ";
  15.  
  16. }
  17. cout<<endl;
  18. return;
  19.  
  20. }
  21. ans.push_back(arr[i]);
  22. printSubsets(arr,ans,i+1);
  23.  
  24. ans.pop_back();
  25. printSubsets(arr,ans,i+1);
  26.  
  27.  
  28. }
  29.  
  30. int main(){
  31. std::vector<int> arr1={1,2,3};
  32.  
  33. vector<int>ans;
  34. int i=0;
  35. printSubsets(arr1,ans,i);
  36. return 0;
  37.  
  38. }
Success #stdin #stdout 0.01s 5288KB
stdin
45
stdout
1 2 3 
1 2 
1 3 
1 
2 3 
2 
3