c - How to print the 32 different combinations of a 5-digit access code(2 choices per number(2^5))? -


i trying write program scans in 5-digit key pad access code , returns 32 different ways access code mimicked. means each button has 2 possible choices; therefore, each 5-digit access code has 2^5 = 32 combinations. program returns buttons user has pressed , how many times, i've come brick wall implementing piece of code various combinations equivalent. question is: how can implement code return 32 other equivalent access codes?

the key pad looks this:

(buttons 1-5)

button 1: 1 & 2

button 2: 3 & 4

button 3: 4 & 6

button 4: 7 & 8

button 5: 9 & 0

/*headers*/ #include<stdio.h> #include<stdlib.h> #define size 5   int main (void){    /***** key pad ******/    /*   (buttons 1-5)  button 1: 1 & 2  button 2: 3 & 4  button 3: 4 & 6  button 4: 7 & 8  button 5: 9 & 0 */ /***** key pad**** */    /* data */ unsigned int input1[2]; unsigned int input2[2]; unsigned int input3[2]; unsigned int input4[2]; unsigned int input5[2]; unsigned int x=0; unsigned int i=0; unsigned int j=0; unsigned int k=0; unsigned int l=0; unsigned int m=0; unsigned int z=0;   for(z=0;z<15;z++){  printf("--");  } printf("\n"); printf("\t*** key pad ***\n"); printf("button 1: 1 or 2\n"); printf("button 2: 3 or 4\n"); printf("button 3: 5 or 6\n"); printf("button 4: 7 or 8\n"); printf("button 5: 9 or 0\n");   for(z=0;z<15;z++){  printf("--");  }  printf("\n");  /* code enter integers key pad */ printf("enter 5 digit lab access code\n"); printf("type 1 number @ time , press 'enter' after each digit\n"); scanf("%d%d%d%d%d", &input1, &input2, &input3, &input4, &input5);     if( input1 == 1 || input1 == 2){       input1[0] = 2;       input1[1] = 1;           }else{ if(input1 == 3 || input1 == 4){        input1[0] = 4;        input1[1] = 3;           }else{ if(input1 == 5 || input1 == 6){        input1[0] = 6;        input1[1] = 5;           }else{ if(input1 == 7 || input1 == 8){       input1[0] = 8;       input1[1] = 7;           }else{ if(input1 == 9 || input1 == 0){       input1[0] = 9;       input1[1] = 0;  }}}}}//end if/else      if( input2 == 1 || input2 == 2){       input2[0] = 2;       input2[1] = 1;           }else{ if(input2 == 3 || input2 == 4){        input2[0] = 4;        input2[1] = 3;            }else{ if(input2 == 5 || input2 == 6){        input2[0] = 6;        input2[1] = 5;           }else{ if(input2 == 7 || input2 == 8){        input2[0] = 8;        input2[1] = 7;           }else{ if(input2 == 9 || input2 == 0){        input2[0] = 9;        input2[1] = 0;  }}}}}//end if/else     if( input3 == 1 || input3 == 2){       input3[0] = 2;       input3[1] = 1;           }else{  if(input3 == 3 || input3 == 4){      input3[0] = 4;      input3[1] = 3;           }else{  if(input3 == 5 || input3 == 6){      input3[0] = 6;      input3[1] = 5;           }else{ if(input3 == 7 || input3 == 8){     input3[0] = 8;     input3[1] = 7;           }else{ if(input3 == 9 || input3 == 0){      input3[0] = 9;      input1[1] = 0;  }}}}}//end if/else     if( input4 == 1 || input4 == 2){      input4[0] = 2;      input4[1] = 1;           }else{ if(input4 == 3 || input4 == 4){      input4[0] = 4;      input4[1] = 3;           }else{ if(input4 == 5 || input4 == 6){      input4[0] = 6;      input4[1] = 5;           }else{ if(input4 == 7 || input4 == 8){      input4[0] = 8;      input4[1] = 7;           }else{ if(input4 == 9 || input4 == 0){      input4[0] = 9;      input4[1] = 0;   }}}}}//end if/else      if( input5 == 1 || input5 == 2){      input5[0] = 2;      input5[1] = 1;            }else{ if(input5 == 3 || input5 == 4){      input5[0] = 4;      input5[1] = 3;           }else{ if(input5 == 5 || input5 == 6){      input5[0] = 6;      input1[1] = 5;           }else{ if(input5 == 7 || input5 == 8){      input5[0] = 8;      input5[1] = 7;           }else{ if(input5 == 9 || input5 == 0){      input5[0] = 9;      input5[1] = 0;   }}}}}    (i=0; i<2; i++) {     (j=0; j<2; j++) {         (k=0; k<2; k++) {            (l=0; l<2; l++) {               (m=0; m<2; m++) {     printf("%d%d%d%d%d\n", input1[i], input2[j], input3[k], input4[l], input5[m]);         }     }     }      }   }      printf("\n\n");    for(z=0;z<15;z++){   printf("--");   }   printf("\n\n");           }//end of main 

here's example, in java, 3 digits. use 2 element array each digit, it's initialized button 0 settings, need logic initialize actual button setttings, idea pretty straightforward, should able extend easily:

    int[] dig1 = new int[2];     int[] dig2 = new int[2];     int[] dig3 = new int[2];     dig1[0] = 0;     dig1[1] = 9;     dig2[0] = 0;     dig2[1] = 9;     dig3[0] = 0;     dig3[1] = 9;     (int i=0; i<2; i++) {         (int j=0; j<2; j++) {             (int k=0; k<2; k++) {                 system.out.println(dig1[i]+" " + dig2[j] + " "+dig3[k]);             }         }     } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -