samedi 24 février 2018

reducing if statements in C for efficiency

I am trying to make my code more efficient by reducing the number of conditional statements as I am going to write the code in assembly in the future. Do you guys see any way to reduce the statements to be more efficient?

     if (j==18)
       {
          store=12;
       }
     else if(j==30)
       {
        store=10;
       }
     else if(j==42)
     {
        store=8;
     }
     else if(j==54)
       {
        store=6;
       }
     else if(j==66)
       {
        store=4;
       }
     else if(j==78)
       {
        store=2;
       }
       else if(j==92)
       {
        store=2;
       }
         else if(j==106)
       {
        store=4;
       }
         else if(j==120)
       {
        store=6;
       }
         else if(j==134)
       {
        store=8;
       }
        else if(j==148)
       {
        store=10;
       }
         else if(j==162)
       {
        store=12;
       }
       else store=1;    

Aucun commentaire:

Enregistrer un commentaire