fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int stack[100], n;
  6.  
  7. void subsets(int level) {
  8. if( level <= n ) {
  9. for(int i = stack[level-1]+1; i <= n; ++i) {
  10. stack[level] = i;
  11. for(int j = 1; j <= level;++j)
  12. cout<<stack[j]<<" ";
  13. cout<<endl;
  14. subsets(level+1);
  15. }
  16. }
  17. }
  18.  
  19. int main() {
  20. n = 3;
  21. subsets(1);
  22. }
Success #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout
1 
1 2 
1 2 3 
1 3 
2 
2 3 
3