Puzzle 2D1


Fill an N by M integer array with 0, 1, 2, ... and print it out.

[E-6] Write a main() that declares an N by M integer array and fills it with ascending integers starting with 0. After filling the array, display it on the monitor. Print one row of the array per output line. Let wrap-around take care of long lines.

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.

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

/* Puzzle DD01 — fill an N by M integer array with ascending integers and print it out. */

int main()
{
  const int Nrows = 3, Mcols = 5 ;
  int x[Nrows][Mcols] ;
  
  int count = 0; /* value to copy to the array */
  
  int r, c;  /* row and column indexes for the array */
  
  /* Fill the array with ascending integers */

    
  /* Print out the array */

  
  printf("\n");
  system("PAUSE");	 /* Remove this if not needed */
  return 0;
}

If your compiler complains that the dimensions of x[Nrows][Mcols] cannot be variables, make them pre-processor constants at the top of the source file. You may have to make similar adjustments in the rest of the puzzles of this section.

#define Nrows 3
#define Ncols 5


Answer         Next Page         Previous Page Home