D17 Answer



int initDiagonals ( int x[][NUMCOLS], int nrows )
{
  int r, c, max ;

  /* Find the value for the main diagonal */
  if ( NUMCOLS > nrows ) max = NUMCOLS ;
  else max = nrows ;

  /* Scan through the array, setting element values */
  for ( r=0; r<nrows; r++ )
    for ( c=0; c<NUMCOLS; c++ )
      x[r][c] = max - abs( r-c );
}