1. ## 2d Arrays

Hello I'm confused how to build a 9x9 board using 2d arrays. I attached what my board should look like. I looked at the information online for help but i couldn't really understand. I want to build the board and understand how to print and edit the arrays. If you could help me understand that would be great. this is what i have so far.

Code:
```#include <stdio.h>
# define length 9
# define width 9

int main (void){
int row;
int col;
int i=0;
int count=0;
int mines;
int randomseed;

scanf("%d", &randomseed);

printf("please input the number of mines: ");
scanf("%d", &mines);

//create the gameboard size
int gameboard[length][width];

//for each row
for(row=0; row<length; row++)
{
//for each col
for(col=0; col<width; col++)
{
scanf("%d", &i);
gameboard[row][col]=i;
}
}

//for each row
for(row=0; row<length; row++)
{
//for each col
for(col=0; col<width; col++)
{
//prints an X in place of every 1
if(gameboard[row][col]==1)
{
printf("X ");
}
//prints out the other numbers for how many mines are found by each space
else
{
//finds 0's and checks how many X's are around them
if(gameboard[row][col]==0)
{
count = 0;
if(gameboard[row][col+1]==1)
{
count=count+1;
}
if(gameboard[row][col-1]==1)
{
count=count+1;
}
if(gameboard[row+1][col]==1)
{
count=count+1;
}
if(gameboard[row-1][col]==1)
{
count=count+1;
}
if(gameboard[row+1][col+1]==1)
{
count=count+1;
}
if(gameboard[row+1][col-1]==1)
{
count=count+1;
}
if(gameboard[row-1][col+1]==1)
{
count=count+1;
}
if(gameboard[row-1][col-1]==1)
{
count=count+1;
}

printf("%d ", count);
}
}
}

printf("\n");
}

printf("\n");
return 0;
}```

2. Just reposting code after formatting since it is hard to read

Code:
```#include <stdio.h>
# define length 9
# define width 9

int main (void)
{
int row;
int col;
int i=0;
int count=0;
int mines;
int randomseed;

scanf("%d", &randomseed);

printf("please input the number of mines: ");
scanf("%d", &mines);

//create the gameboard size
int gameboard[length][width];

//for each row
for(row=0; row<length; row++)
{
//for each col
for(col=0; col<width; col++)
{
scanf("%d", &i);
gameboard[row][col]=i;
}
}

//for each row
for(row=0; row<length; row++)
{
//for each col
for(col=0; col<width; col++)
{
//prints an X in place of every 1
if(gameboard[row][col]==1)
{
printf("X ");
}
//prints out the other numbers for how many mines are found by each space
else
{
//finds 0's and checks how many X's are around them
if(gameboard[row][col]==0)
{
count = 0;
if(gameboard[row][col+1]==1)
{
count=count+1;
}
if(gameboard[row][col-1]==1)
{
count=count+1;
}
if(gameboard[row+1][col]==1)
{
count=count+1;
}
if(gameboard[row-1][col]==1)
{
count=count+1;
}
if(gameboard[row+1][col+1]==1)
{
count=count+1;
}
if(gameboard[row+1][col-1]==1)
{
count=count+1;
}
if(gameboard[row-1][col+1]==1)
{
count=count+1;
}
if(gameboard[row-1][col-1]==1)
{
count=count+1;
}

printf("%d ", count);
}
}
}

printf("\n");
}

printf("\n");
return 0;
}```

3. You need to be careful about how you check the borders. For example, when "col == 0" don't use "[col - 1]" and when "col == width-1" don't use "[col + 1]".

4. You have not given us enough information to help you. For instance:

1. What exactly is the input supposed to consist of?
2. What are the rules for transforming this input into the final result?

Printing two-dimensional arrays is easy, you just need to use nested loops, of which your code already makes use of in several places. To determine whether to print a number or a symbol, just check the value at each location with an "if()" and print the desired output, based on the value at that location. You'd also want to print a newline after each row - you should be able to reason out where exactly this should be placed.

Editing arrays is also easy, you just need to assign a value to a particular location. If you want to cycle through the entire array, again you just use nested loops, and assign values to each location as needed.

I suspect you're supposed to receive input into the array, then cycle through the array and update the values according to a certain set of rules (though this is just a guess since you didn't give us a complete description of the expected program behavior). However, you're not updating the array in your code, you're just printing the result to the screen. You can just change the print statement (printf("%d ", count);) to an assignment (gameboard[row][col] = count;). And, as GReaper mentioned, make sure you don't go outside the bounds of your array.

Code:
```# define length 9
# define width 9```
Though this is not wrong, by convention, named constants are typically in all caps.