I'm trying to come up with something to change the tile numbers in the last two array slots, containing numbers 1 and 2 when I have an odd number of tiles. I thought this would work, but when I print out the values using draw(), it prints the 1 and 2 in the same place as it would if I had an even number of tiles. Here is my code:

void init(void)
    int count=(d*d)-1;

    for (int i=0; i<d;i++)
        for (int j=0; j<d;j++)
        if ((d*d)%2==0)

           // printf("odd %i %i  \n", board[d][d-2],  board[d][d-1]);

That print function was just there to see if the values were actually changing and that the if statement was recognizing an odd number of tiles, which it does! Still, it won't show up properly when I call draw().

2 Answers 2


Recall that arrays are zero based. So if you have an array of d elements, the index goes from 0 to d - 1.

  • gah! wow so obvious but thank you! Commented Jul 17, 2014 at 13:47

board[d][d-2] is not available in array -- board.

if d = 3; the last element in the array would be board[2][2] not board[3][3], which is board[d][d].

The index starts from 0 finishes at 2.

You must log in to answer this question.

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