fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n, a[10], d = 1;
  5.  
  6. void pr() {
  7. cout<< d<< ": ";
  8. for (int i = 0; i < n; i++)
  9. cout << a[i]<< " ";
  10. cout << endl;
  11. d++;
  12. }
  13.  
  14. void binary(int i) {
  15. for (int j = 0; j <= 1; j++) {
  16. a[i] = j;
  17. if (i == n - 1)
  18. pr();
  19. else
  20. binary(i + 1);
  21. }
  22. }
  23.  
  24. int main() {
  25. cin >> n;
  26. binary(0);
  27. }
  28.  
Success #stdin #stdout 0.01s 5272KB
stdin
5
stdout
1: 0 0 0 0 0 
2: 0 0 0 0 1 
3: 0 0 0 1 0 
4: 0 0 0 1 1 
5: 0 0 1 0 0 
6: 0 0 1 0 1 
7: 0 0 1 1 0 
8: 0 0 1 1 1 
9: 0 1 0 0 0 
10: 0 1 0 0 1 
11: 0 1 0 1 0 
12: 0 1 0 1 1 
13: 0 1 1 0 0 
14: 0 1 1 0 1 
15: 0 1 1 1 0 
16: 0 1 1 1 1 
17: 1 0 0 0 0 
18: 1 0 0 0 1 
19: 1 0 0 1 0 
20: 1 0 0 1 1 
21: 1 0 1 0 0 
22: 1 0 1 0 1 
23: 1 0 1 1 0 
24: 1 0 1 1 1 
25: 1 1 0 0 0 
26: 1 1 0 0 1 
27: 1 1 0 1 0 
28: 1 1 0 1 1 
29: 1 1 1 0 0 
30: 1 1 1 0 1 
31: 1 1 1 1 0 
32: 1 1 1 1 1