Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [1,1]
- [0,1]
- [1,0]
- [1,1]
- [1,1,1]
- [0,1,1]
- [1,0,1]
- [0,0,1]
- [1,1,0]
- [0,1,0]
- [1,0,0]
- [0,0,0]
- 0 0 1
- 1 0 0
- 0 0 32563
- 0 32765 0
- 32765 0 0
- 1664188935 3 -1
- #include<stdio.h>
- int pow_2(int digit); /*2の引数乗を戻す*/
- void make_binary(int len1,int len2, int n, int (*a)[n]);
- /*len1(=len2)×nの二次元配列に0または1を代入し,n桁?の全ての2進数を作成*/
- int main(void){
- int i,j;
- int digit,len;
- digit=3;
- len=pow_2(digit);
- int a[len][digit]; /*ここでは,3桁の二進数(先頭が0でも良い)が8通り存在するので8×3の配列を用意*/
- make_binary(len, len, digit-1,a);
- for(i=0; i<len; i++)『
- for(j=0; j<digit; j++){
- printf("%d ",a[i][j]);
- }
- printf("n");
- }
- return 0;
- }
- int pow_2(int digit){
- int i;
- int a=1;
- for(i=0; i<digit; i++){
- a=a*2;
- }
- return a;
- }
- void make_binary(int len1,int len2, int n, int (*a)[n]){
- int i,j;
- i=0;
- if (n==-1){
- return ;
- }
- else{
- while(i<len1){
- for(j=0; j<len2/2; j++){
- printf("%d %d ",i,j);
- printf("n");
- a[i++][n]=1;
- }
- for(j=len2/2; j<len2; j++){
- printf("%d %d ",i,j);
- printf("n");
- a[i++][n]=0;
- }
- }
- make_binary(len1, len2/2, n-1, a);
- }
- }
- void make_binary(int len1,int len2, int n, int (*a)[n])
- void make_binary(int len1,int len2, int x, int y, int a[x][y])
- make_binary(len1, len2, (max - 1), (digit -1), a);
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void makeArray(int digit);
- int main(int argc, const char * argv[]) {
- // insert code here...
- int digit = atoi(argv[1]);
- makeArray(digit);
- return 0;
- }// end int main
- void makeArray(int digit)
- {
- int max = pow(2, digit);
- // allocate allay
- unsigned short array[max][digit];
- // create data
- int currentBit = 0;
- int value = 0;
- for (value = max - 1; value >= 0; value--) { // 最大値 -1 から0まで逆順に
- for (currentBit = digit - 1; currentBit >= 0; currentBit--) { // 大きい方のビットから小さい方のビットへ
- // ビット演算の値が0なら、0, そうでないならそのビットは1
- array[value][currentBit] = (value & (1 << currentBit)) == 0 ? 0 : 1;
- }// end foreach bit
- }// end foreach value
- // print value
- for (value = max - 1; value >= 0; value--) {
- printf("%d : [", value);
- for (currentBit = digit - 1; currentBit >= 0; currentBit--) {
- if (currentBit != 0) {
- printf("%d,", array[value][currentBit]);
- } else {
- printf("%d", array[value][currentBit]);
- }
- }// end foreach bit
- printf("]n");
- }// end foreach value
- }// end int **makeArray
- void make_binary(int len1,int len2, int n, int (*a)[n]);
- make_binary(len, len, digit-1,a);
- make_binary(len1, len2/2, n-1, a);
- (オフセットは`int`単位)
- +-----------+-----------+-----------+
- a -> |[0][0]-> +0|[0][1]-> +1|[0][2]-> +2|
- +-----------+-----------+-----------+
- |[1][0]-> +3|[1][1]-> +4|[1][2]-> +5|
- +-----------+-----------+-----------+
- |... |
- +-----------+-----------+
- a -> |[0][0]-> +0|[0][1]-> +1|
- +-----------+-----------+
- |[1][0]-> +2|[1][1]-> +3|
- +-----------+-----------+
- |[2][0]-> +4|[2][1]-> +5|
- +-----------+-----------+
- |... |
- void make_binary(int len1, int len2, int n, int size, int (*a)[size]);
- make_binary(len, len, digit-1, digit, a);
- make_binary(len1, len2/2, n-1, size, a);
Add Comment
Please, Sign In to add comment