title: How to count groups of numbers in two dimensional array?
body: <p>I have field from two dimensional array in which 1 is a land and 0 is nothing. When two lands stay on the same wall are called neighbors. When a land have no neighbors is called island and when it has two or more neighbors is called continent. I have to count all the islands and continents on the field. This is how i find the islands.</p>
  
  <pre><code>int find_islands(const int array[][8]) { // Find the islands in the field.
  int count = 0;
  for (int i = 0; i &lt; 8; i++)
  {
      for (int x = 0; x &lt; 8; x++)
      {
          if (array[i][x] == 1)
          {
  
              if (i == 0)
              {
                  if (x == 0)
                  {
                      if (array[i][x + 1] == 0 &amp;&amp; array[i + 1][x] == 0)
                      {
                          count++;
                      }
                  }
                  else if (x == 7)
                  {
                      if (array[i][x - 1] == 0 &amp;&amp; array[i + 1][x] == 0)
                      {
                          count++;
                      }
                  }
                  else
                  {
                      if (array[i][x + 1] == 0 &amp;&amp; array[i][x - 1] == 0 &amp;&amp; array[i + 1][x] == 0)
                      {
                          count++;
                      }
                  }
  
              }
  
              else if (i == 7)
              {
                  if (x == 0)
                  {
                      if (array[i][x + 1] == 0 &amp;&amp; array[i - 1][x] == 0)
                      {
                          count++;
                      }
                  }
                  else if (x == 7)
                  {
                      if (array[i][x - 1] == 0 &amp;&amp; array[i - 1][x] == 0)
                      {
                          count++;
                      }
                  }
                  else
                  {
                      if (array[i][x + 1] == 0 &amp;&amp; array[i][x - 1] == 0 &amp;&amp; array[i - 1][x] == 0)
                      {
                          count++;
                      }
                  }
              }
  
              else
              {
                  if (x == 0)
                  {
                      if (array[i][x + 1] == 0 &amp;&amp; array[i + 1][x] == 0 &amp;&amp; array[i - 1][x] == 0)
                      {
                          count++;
                      }
                  }
                  else if (x == 7)
                  {
                      if (array[i][x - 1] == 0 &amp;&amp; array[i + 1][x] == 0 &amp;&amp; array[i - 1][x] == 0)
                      {
                          count++;
                      }
                  }
                  else
                  {
                      if (array[i][x + 1] == 0 &amp;&amp; array[i][x - 1] == 0 &amp;&amp; array[i + 1][x] == 0 &amp;&amp; array[i - 1][x] == 0)
                      {
                          count++;
                      }
                  }
  
              }
          }
      }
  }
  return count;}
  </code></pre>
  
  <p>This is a sample array.</p>
  
  <pre><code>int board[8][8] = {
      {0, 1, 0, 0, 1, 1, 0, 0},
      {0, 0, 0, 0, 0, 0, 0, 0},
      {1, 1, 0, 0, 1, 0, 0, 0},
      {1, 1, 0, 0, 1, 0, 0, 1},
      {0, 0, 0, 1, 0, 1, 0, 0},
      {0, 0, 0, 0, 0, 0, 0, 0},
      {1, 1, 1, 1, 1, 0, 0, 0},
      {1, 0, 0, 1, 1, 0, 1, 0} };
  </code></pre>
  
  <p>My problems is that i cant think of a way to find the continents. Thanks in advance!</p>