Problem description
For a 01-string length of 5 bits, each bit can be 0 or 1, a total of 32 possible. The first few of them are:
00000
00001
00010
00011
00100
Please output these 32 kinds of 01 strings in order from small to large.
Input format this question is not entered. Output format output 32 rows, in order from small to large in each row a length of 5 01 strings. Sample Output 00000
00001
00010
00011
< The following sections omit > Experience: This topic reminds me of the idea of using an integer array to hold a large number first, each time it starts with the first element and then adjusts. For each element in the array does not overflow, use while () to resolve.
1# include <stdio.h>2 intMainvoid)3 {4 inta[5]={0};5 inttemp;6 intTimes ;7 inti;8printf"00000\n");9 for(times=1; times<= to; times++)Ten { OneI=0; Aa[i]+=1; - while(a[i]>=2) - { thetemp=a[i]/2; -a[i]=a[i]%2; -i++; -a[i]=a[i]+temp; + } - for(i=4; i>=0; i--) + { Aprintf"%d", A[i]); at } -printf"\ n"); - }
return 0; -}
Code:
"Blue Bridge Cup" basic exercise: 01 Strings