AlexandruT

Generarea submultimilor multimii {1, 2, ... , n}

Dec 9th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[20];
  6.  
  7. int main()
  8. {
  9.     int n, i;
  10.     cin >> n;
  11.     for(i = 1; i <= n; i++) a[i] = 0;
  12.     while(a[0] == 0)
  13.     {
  14.         for(i = 1; i <= n; i++) if(a[i] == 1) cout << i << " ";
  15.         cout << "\n";
  16.         for(i = n; a[i] == 1; i--) a[i] = 0;
  17.         a[i] = 1;
  18.     }
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment