x2311

Untitled

Dec 22nd, 2021
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cout << "N:";
  9.     cin >> n;
  10.  
  11.     int a[n];
  12.     for (int i = 0; i < n; i++) {
  13.         a[i] = 0;
  14.     }
  15.     for (int i = 0; i < pow(2, n); i++) {
  16.         for (int j = n-1; j >= 0; j--) {
  17.             cout << a[j];
  18.         }
  19.         cout << endl;
  20.         for (int j = 0; j < n; j++) {
  21.             if (j == 0 || (i+1) % (int)pow(2,j) == 0) {
  22.                 if (a[j] == 1) {
  23.                     a[j] = 0;
  24.                 } else {
  25.                     a[j] = 1;
  26.                 }
  27.  
  28.             }
  29.         }
  30.     }
  31. }
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment