title: Find intersection in 2d arrays
body: <p>I wrote a small code to find intersection of two 2d array, unfortunately it is not working, so maybe you can help me.. Intersection is, if both numbers on place (x,y) is a "1". Otherwise there should be "0"</p>
  
  <pre><code>void intersection(int *mat, int rows, int cols) {    
      int rows1 = 5, cols1 = 4; // secend matrix is in function because i just need it here
      int ma2[] = { 0, 0, 1, 0, 1, // 1. Zeile
                    0, 0, 1, 0, 1, // 2. Zeile
                    0, 0, 1, 1, 0, // 3. Zeile
                    0, 0, 1, 0, 0  // 4. Zeile
                  }; 
  
      int i = 0;
      int j = 0;
      int x = 0;
      int y = 0;
  
      while (j &lt; cols &amp;&amp; y &lt; cols1) { // maybe it is better with a for loop ??
      j += 1;
      y += 1;
      while (i &lt; rows &amp;&amp; x &lt; rows1) {
          i += 1;
          x += 1;
          if (mat[j*rows+i] == 1 &amp;&amp; ma2[y*rows1+x] == 1) {
              printf("%d ", mat[j*rows+i]);
              break;
              } else {
              printf("%d ", mat[j*rows+i]);
              break;
              }
      }
          printf("\n");
      }
  }
  
  
  int main (void) {
      int rows = 5, cols = 4;  //first matrix is in main, because i need it for other functions
      int ma[] = { 0, 0, 1, 0, 0, // 1. Zeile
                   1, 0, 0, 0, 0, // 2. Zeile
                   1, 0, 1, 0, 0, // 3. Zeile
                   0, 0, 1, 0, 0  // 4. Zeile
                  };
  
      intersection(ma, rows, cols);
      return 0;          
  }
  </code></pre>
  
  <p>Output should be (in this case):</p>
  
  <pre><code>           { 0, 0, 1, 0, 0, // 1. Zeile
               0, 0, 0, 0, 0, // 2. Zeile
               0, 0, 1, 0, 0, // 3. Zeile
               0, 0, 1, 0, 0  // 4. Zeile
              };
  </code></pre>
  
  <p>but i just get a matrix with 1 row </p>
  
  <p>Greets ;)</p>