Answer 2D3

#include <stdio.h>
#include <stdlib.h>
 
void print2DArray ( int nrows, int ncols, int x[nrows][ncols] )
{
  int r, c;
  for ( r=0; r<nrows; r++ )
  {
    for ( c=0; c<ncols; c++ )
      printf("%3d,", x[r][c] );
    printf("\n");
  }
}

const int ROWS = 5;
const int COLS = 9;

int main()
{
  int x[ROWS][COLS] ;
  int count = 0;
  
  int r, c;  /* row and column indexes */
  
  /* Fill the array with ascending integers */
  for ( r=0; r<ROWS; r++ )
    for ( c=0; c<COLS; c++ )
      x[r][c] = count++ ;
    
  /* Print the array using your function */
  print2DArray( ROWS, COLS, x );
  
  printf("\n");
   
  return 0;
}


Back to Puzzle Home