How am I supposed to fill up a 2D array?
I've managed to get away with the following:
It works fine, but is it correct?Code:#include <stdio.h> int main() { int board[3][3] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; int a, b; int i; int j; for (i = 0;i < 3; i++) { for (j = 0; j < 3; j++) { printf("%d", board[i][j]); } printf("\n"); } printf("Input a: "); scanf("%d", &a); printf("Input b: "); scanf("%d", &b); board[a][b] = 1; for (i = 0;i < 3; i++) { for (j = 0; j < 3; j++) { printf("%d", board[i][j]); } printf("\n"); } getchar(); getchar(); }
Thank You!
(I mean with pre-set numbers, I understand that you could fill it with zeros just by using a loop.)



LinkBack URL
About LinkBacks


