Answer 2D4
#include <stdio.h>
#include <stdlib.h>
/* Puzzle D04 -- print an N by M integer array*/
void print2DArray ( int nrows, int ncols, int *x )
{
int r, c; /* row and column indexes for the array */
/* Print elements in row major order */
for ( r=0; r<nrows; r++ )
{
for ( c=0; c<ncols; c++ )
printf("%3d ", *(x+ncols*r+c) );
printf("\n");
}
}
int main()
{
int x[3][7] = { { 0, 1, 2, 3, 4, 5, 6},
{ 7, 8, 9, 10, 11, 12, 13},
{14, 15, 16, 17, 18, 19, 20} };
/* Print the array using our function */
print2DArray( 3, 7, (int *)x );
printf("\n");
return 0;
}