intmain() { for (int i = 0; i < 32; i++) { int t = i, j = 5; int v[] = {0, 0, 0, 0, 0}; for (int j = 0; t > 0; j++) { v[j] = t % 2; t = t / 2; } for (int k = 4; k >= 0; k--) { cout << v[k]; } cout << endl; }
system("pause"); return0; }
另外附上在网上看到的很牛的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include<iostream>
usingnamespace std;
intmain() { int i; for (i = 0; i < 32; i++) cout << i / 16 % 2 << i / 8 % 2 << i / 4 % 2 << i / 2 % 2 << i % 2 << endl;