title: Subtracting a value from lines of a matrix
body: <p>I have the following matrix:</p>
  
  <p>1 4 5</p>
  
  <p>5 7 6</p>
  
  <p>5 8 8 </p>
  
  <p>I want to find the minimum value of line 1 and subtract from all values of the same line. The same thing for line 2 and 3. The minimum value of line 1 is 1, line 2 is 5 and line 3 is 5. So I subtract 1 from all values of line 1, subtract 5 from all values in line 2 and subtract 5 from all values in line 3.</p>
  
  <p>0 3 4</p>
  
  <p>0 2 1</p>
  
  <p>0 3 3</p>
  
  <p>My matrix is called "a":</p>
  
  <pre><code>min = a[0][0]  \\\ min = minimum value
  
  for (k = 0; k &lt; 3; k++) {
  
          for (l = 1; l &lt; 3; l++) {
              if (a[k][l] &lt; min)
                  min = a[k][l - 1];
  
          }
  
          for (l = 0; l &lt; 3; l++) {
  
              a[k][l] = a[k][l] - min;
  
          }
          min = a[k+1][0];
  
      }
  </code></pre>
  
  <p>For k = 0, the value a[k+1][0] = 5 is changing to 4. Why is that?</p>
  
  <p>EDIT: I declared the array as:</p>
  
  <pre><code>a[0][0] = 1;
  a[0][1] = 4;
  a[0][2] = 5;
  a[1][0] = 5;
  a[1][1] = 7;
  a[1][2] = 6;
  a[2][0] = 5;
  a[2][1] = 8;
  a[2][2] = 8;
  </code></pre>
  
  <p>Following Kresimir I changed the code to:</p>
  
  <pre><code>  for (k = 0; k &lt; 3; k++) {
  
      min = 10000;
      for (l = 0; l &lt; 3; l++) {
          if (a[k][l] &lt; min)
              min = a[k][l];                      
      }
  
      for (l = 0; l &lt; 3; l++) {           
          a[k][l] = a[k][l] - min;
      }
  
  }
  </code></pre>
  
  <p>To print the matrix:</p>
  
  <pre><code>  for (i = 0; i &lt; 3; i++) {
  
      for (j = 0; j &lt; 3; j++) {
          printf("a[%d][%d] = %d\n", i, j, a[i][j]);
      }
  }
  </code></pre>
  
  <p>But the output is:</p>
  
  <pre><code>a[0][0] = 0
  a[0][1] = 3
  a[0][2] = 0
  a[1][0] = 0
  a[1][1] = 3
  a[1][2] = 0
  a[2][0] = 0
  a[2][1] = 0
  a[2][2] = 3
  </code></pre>
  
  <p>When k = 0, the first line is changed correctly and the rest is kept the same as they should, when k = 1, all lines are changed wrong to the above.</p>