# My code is swapping "1", "2" even if i have written code only for swapping "if even."

This is my init function, please check and suggest:

``````void init(void)
{
int size= d*d;
for (int i=0;i<d;i++)
{
for (int j=0;j<d;j++)
{
board[i][j]=size-1;
size -= 1;
}
}
//if even
if (size%2==0)
{
board [d-1][d-2]=2;
board [d-1][d-3]=1;
}
}
``````

I changed code little bit and now working fine before change`if (size%2==0)` now after change it is`if ((d*d)%2==0)`, both means the same in my opinion but this one worked. In the code size is defined as`size=d*d`.

• size starts out as d*d, but gets decremented in the loop(s) and is something like 0 by the time you get here `if (size%2==0)` Sep 10, 2016 at 12:16

@DinoCoderSaurus called it in the comments again.

The computer does exactly what you tell it to do, not what you think it should be doing in your opinion. In this case, you have assigned an expected value to a variable, then changed that value (to something unexpected!) before checking something based on its expected value.

Hope this helps.