Puzzle 2D2


Initialize an array and print it out.

[E-6] An array initializer can be used when an array is declared. The following declares a 3 row, 4 column array of int and initializes it.

int myArray[3][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, -2, 9, 23} };

The dimensions of the array must both be specified as constants. (You can't use variables.) Often preprocessor symbols are used (as below.)

Here is a skeleton of the program. Your job is to finish it. Use copy-and-paste to copy this code into a source file. Pick whatever dimensions you want.

#include <stdio.h>
#include <stdlib.h>

/* Puzzle DD02 — Initialize an integer array and print it out. */
#define Nrows ....
#define Mcols ....

int main()
{
 
  int x[Nrows][Mcols] = { ...... } ;
    
  int r, c;  /* row and column indexes for the array */
    
  /* Print out the array */
 
  printf("\n"); /* Remove this if not needed */
  return 0;
}


Answer         Next Page         Previous Page Home