1

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;
    }
}

2 Answers 2

0

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

1
  • 2
    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) Commented Sep 10, 2016 at 12:16
0

@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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .