Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To begin, ask yourself: <strong>"How would I create a box?"</strong> To create a box, you need <strong>4 sides</strong>. <em>However</em>, <strong>the simplest box that one can make is involves two lines</strong>, as we can take <strong>the height of the box to be zero - or <em>infinitesimal</em></strong>. In code, you'll need at least 2 rows to make a box.</p> <p>Like so:</p> <pre><code>000000000000000 000000000000000 </code></pre> <p>However, it has <strong>no height.</strong> In other words, <strong>this is a zero-height bordered box.</strong></p> <p>Thus to create a box like this:</p> <pre><code>000000000000000 011111111111110 000000000000000 </code></pre> <p>What do you notice? <strong>The first and the last rows are all zeroes. <em>And</em>, the first and last element of the middle row is a zero, everything else on that row is a 1.</strong></p> <p>Extending further:</p> <pre><code>000000000000000 011111111111110 011111111111110 000000000000000 </code></pre> <p><strong>We see the same pattern - so this can be extended for the nth row case.</strong> Thus, the algorithm is: </p> <ol> <li>First and last rows are all zeros. </li> <li>For all other rows, the first and last columns of those rows are all 0. </li> <li>Everything else is set to 1.</li> </ol> <p>Hence, in your case:</p> <pre><code>for(r=0; r&lt; ROWS; r++) { for(c=0; c &lt; COLS; c++) { if (r == 0 || r == ROWS - 1) { M[r][c]=0; } else if(c == 0 || c == COLS -1) { M[r][c]=0; } else { M[r][c]=1; } cout&lt;&lt; M[r][c]; } cout &lt;&lt; endl; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload