fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. unsigned digits;
  6. std::cin >> digits;
  7. for(unsigned i = 0; i < (1 << digits); ++i)
  8. {
  9. for(unsigned j = digits; j > 0; --j)
  10. {
  11. std::cout << ((i >> (j - 1)) % 2) << " ";
  12. }
  13. std::cout << std::endl;
  14. }
  15. }
  16.  
Success #stdin #stdout 0s 3300KB
stdin
4
stdout
0 0 0 0 
0 0 0 1 
0 0 1 0 
0 0 1 1 
0 1 0 0 
0 1 0 1 
0 1 1 0 
0 1 1 1 
1 0 0 0 
1 0 0 1 
1 0 1 0 
1 0 1 1 
1 1 0 0 
1 1 0 1 
1 1 1 0 
1 1 1 1