/* File: array.c Description: This code sets up a two demensional array and prints out the contents of each locaion. Revised from program 8.7 in Bronson page 405 */ #include #include #define NUMROWS 3 #define NUMCOLS 4 int main() { int i, j; int val[NUMROWS][NUMCOLS] = { 8,16,9,52, 3,15,27,6, 14,25,2,10 }; /* explicitly print out each element of the array */ printf("\nDisplay of val array by explicit element"); printf("\n%2d %2d %2d %2d", val[0][0],val[0][1],val[0][2],val[0][3]); printf("\n%2d %2d %2d %2d", val[1][0],val[1][1],val[1][2],val[1][3]); printf("\n%2d %2d %2d %2d", val[2][0],val[2][1],val[2][2],val[2][3]); /* loop through and print out the array */ printf("\n\nDisplay of val array using a nested for loop"); for (i = 0; i < NUMROWS; i++) { printf("\n"); /* start a new line for each row */ for (j = 0; j < NUMCOLS; j++) printf("%2d ", val[i][j]); } printf("\n"); return EXIT_SUCCESS; }