Advertisement
Josif_tepe

Untitled

Jun 12th, 2022
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <stack>
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n = 3;
  10.    
  11.     for(int bitmask = 0; bitmask < (1 << n); bitmask++) { // (1 << n) = power(2, n)
  12.         for(int bit = 0; bit < n; bit++) {
  13.             if(bitmask & (1 << bit)) {
  14.                 cout << bit + 1 << " " ;
  15.             }
  16.         }
  17.         cout << endl;
  18.     }
  19.     return 0;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement