I'm creating a program that depends on a set of 2d arrays. In the part that I'm currently working on, the user first inputs the desired (square' side) size and the program is supposed to initialize all the arrays and fill them with 0's, except for the 0 row and column, where labels are to be. The resulting array has to look somewhat like this:
0 1 2 3 4 ...
1 0 0 0 0 ...
2 0 0 0 0 ...
3 0 0 0 0 ...
4 0 0 0 0 ...
...
The code I've written looks okay, but once the labeling was implemented, the whole inside (labels not affected) started filling up with some random numbers, with 0's appearing about every 2nd field. This piece of code is made to work independently for now, but I'll move some of the variables out to global scope for connecting the pieces:
int show_Board(int size){
size++;
int board[size][size];
int i=0, x=0;
for (i=0; i<size; i++){ //filling up the array
for (x=0; x<size; x++){
board[i][x]=0;
}
for (i=0; i<=size; i++){ //filling in labels on the borders
board[i][0]=i; // only row 0 breaks if this loop is disabled
for (x=0; x<=size; x++){
board[0][x]=x;
}
}
}
for (i=0; i<size; i++){ //displaying the result
for (x=0; x<size; x++){
cout <<" "<< board[i][x];
}
cout << endl;
}
}
int main(){
show_Board(20);
}
My question is how to make it so that the array fills up correctly (ie. labels and 0's)?