Advertisement
Josif_tepe

Untitled

Feb 28th, 2022
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     for(int mask = 0; mask < (1 << n); mask++) {
  9.         for(int i = 0; i < n; i++) {
  10.             if(mask & (1 << i)) {
  11.                 cout << i << " ";
  12.             }
  13.         }
  14.         cout << endl;
  15.     }
  16.  
  17.     return 0;
  18. }
  19.  
  20. // 1010001110101
  21. // 1010001110101
  22. // {1, 2, 3}
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement