0

I've been working on fifteen, and I started with the init function, and I want to make sure I have it right. Other than the part where you swap 1 and 2, does this look right?

    void init(void)
{
    int num = d * d - 1;
    // TODO
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < d; j++) {
            board[i][j] = int num;
            num--;
        }
    }
}
0
board[i][j] = int num;

You should not declare the type again inside the loop, otherwise it looks good

| improve this answer | |
  • So if I change it to board[i][j] = num; it would be correct? – Joel Banks Jul 23 '17 at 23:33
  • So is! If we say again int num we are actually declaring a new variable visible only inside the for loop – MARS Jul 24 '17 at 12:53

You must log in to answer this question.

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