Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise07.cpp
blob: f2aa288dd43f5b383893944b41b4738a4db91132 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

const unsigned MAX_BITS = 32;

void printBits(unsigned bits, unsigned i, char buffer[MAX_BITS]) {
	if (bits == 0) {
		buffer[i] = '\0';
		std::cout << buffer << std::endl;
	}
	else {
		buffer[i] = '0';
		printBits(bits - 1, i + 1, buffer);
		buffer[i] = '1';
		printBits(bits - 1, i + 1, buffer);
	}
}

int main() {
	unsigned bits;
	std::cin >> bits;

	char buffer[MAX_BITS];
	printBits(bits, 0, buffer);

	return 0;
}