你好麻烦您帮我算下1-255的全部二进制展开表示?
发布网友
发布时间:2022-08-12 23:45
我来回答
共1个回答
热心网友
时间:2024-02-20 01:06
#include<stdio.h>
void f(int n)
{
if(n) f(n/2);
else return;
printf("%d",n%2);
}
int main()
{
int i;
for(i=1;i<=255;i++){
printf("%d:",i);
f(i);
printf("\n");
}
}
/*
运行结果:
1:1
2:10
3:11
4:100
5:101
6:110
7:111
8:1000
9:1001
10:1010
11:1011
12:1100
13:1101
14:1110
15:1111
16:10000
17:10001
18:10010
19:10011
20:10100
21:10101
22:10110
23:10111
24:11000
25:11001
26:11010
27:11011
28:11100
29:11101
30:11110
31:11111
32:100000
33:100001
34:100010
35:100011
36:100100
37:100101
38:100110
39:100111
40:101000
41:101001
42:101010
43:101011
44:101100
45:101101
46:101110
47:101111
48:110000
49:110001
50:110010
51:110011
52:110100
53:110101
54:110110
55:110111
56:111000
57:111001
58:111010
59:111011
60:111100
61:111101
62:111110
63:111111
64:1000000
65:1000001
66:1000010
67:1000011
68:1000100
69:1000101
70:1000110
71:1000111
72:1001000
73:1001001
74:1001010
75:1001011
76:1001100
77:1001101
78:1001110
79:1001111
80:1010000
81:1010001
82:1010010
83:1010011
84:1010100
85:1010101
86:1010110
87:1010111
88:1011000
89:1011001
90:1011010
91:1011011
92:1011100
93:1011101
94:1011110
95:1011111
96:1100000
97:1100001
98:1100010
99:1100011
100:1100100
101:1100101
102:1100110
103:1100111
104:1101000
105:1101001
106:1101010
107:1101011
108:1101100
109:1101101
110:1101110
111:1101111
112:1110000
113:1110001
114:1110010
115:1110011
116:1110100
117:1110101
118:1110110
119:1110111
120:1111000
121:1111001
122:1111010
123:1111011
124:1111100
125:1111101
126:1111110
127:1111111
128:10000000
129:10000001
130:10000010
131:10000011
132:10000100
133:10000101
134:10000110
135:10000111
136:10001000
137:10001001
138:10001010
139:10001011
140:10001100
141:10001101
142:10001110
143:10001111
144:10010000
145:10010001
146:10010010
147:10010011
148:10010100
149:10010101
150:10010110
151:10010111
152:10011000
153:10011001
154:10011010
155:10011011
156:10011100
157:10011101
158:10011110
159:10011111
160:10100000
161:10100001
162:10100010
163:10100011
164:10100100
165:10100101
166:10100110
167:10100111
168:10101000
169:10101001
170:10101010
171:10101011
172:10101100
173:10101101
174:10101110
175:10101111
176:10110000
177:10110001
178:10110010
179:10110011
180:10110100
181:10110101
182:10110110
183:10110111
184:10111000
185:10111001
186:10111010
187:10111011
188:10111100
189:10111101
190:10111110
191:10111111
192:11000000
193:11000001
194:11000010
195:11000011
196:11000100
197:11000101
198:11000110
199:11000111
200:11001000
201:11001001
202:11001010
203:11001011
204:11001100
205:11001101
206:11001110
207:11001111
208:11010000
209:11010001
210:11010010
211:11010011
212:11010100
213:11010101
214:11010110
215:11010111
216:11011000
217:11011001
218:11011010
219:11011011
220:11011100
221:11011101
222:11011110
223:11011111
224:11100000
225:11100001
226:11100010
227:11100011
228:11100100
229:11100101
230:11100110
231:11100111
232:11101000
233:11101001
234:11101010
235:11101011
236:11101100
237:11101101
238:11101110
239:11101111
240:11110000
241:11110001
242:11110010
243:11110011
244:11110100
245:11110101
246:11110110
247:11110111
248:11111000
249:11111001
250:11111010
251:11111011
252:11111100
253:11111101
254:11111110
255:11111111
*/
来自:求助得到的回答