0

I want to represent a sudoku board as a 2-dim array of 2-dim array. The inner array contains 3 rows x 3 columns, making up a box of 9 cells. The outer array should also be 3x3 holding the 9 boxes.

How should I write this structure in C? int board[[3]][[3]]? Of course it is wrong. Is it actually do-able in C?

Thanks!

2 Answers 2

2

In C, you can make a 4 dimensional array, with an outer and inner set of coordinates.

int board[3][3][3][3];

Or you can make a struct to represent the inner board;

struct InnerBoard {
  int board[3][3];
};

InnerBoard board[3][3];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. I think a struct will definitely make the program clearer.
1

What you're looking for is a 4-dimensional array.

int board[3][3][3][3];

The first two indices determine which box, and the second two indices determine which cell inside of the box.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.