Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- int n;
- cout << "N:";
- cin >> n;
- int a[n];
- for (int i = 0; i < n; i++) {
- a[i] = 0;
- }
- for (int i = 0; i < pow(2, n); i++) {
- for (int j = n-1; j >= 0; j--) {
- cout << a[j];
- }
- cout << endl;
- for (int j = 0; j < n; j++) {
- if (j == 0 || (i+1) % (int)pow(2,j) == 0) {
- if (a[j] == 1) {
- a[j] = 0;
- } else {
- a[j] = 1;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment