title: C - Nested loops and stack?
body: <p>I am trying to find the location of a target inside of a 1-D array that acts like a table with rows and cols. I could do it using divide and mod, but I am stuck on finding it using nested loops. specifically, I can't seem to assign values inside the nested loop. 
  here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
     int arr[9] =  // act as a 3 X 3 table
     { 2, 34, 6,
       7, 45, 45,
       35,65, 2
     };
     int target = 7;// r = 1; c = 0
     int r = 0; // row of the target
     int c = 0; // col of the target
     int rows = 3;
     int cols = 3;
     for (int i = 0; i &lt; rows; i++){
         for (int j = 0; j + i * cols &lt; cols + i * cols; i++ ){
             if (arr[j] == target){
             c = j; // columns of the target
             r = i; // rows of the target
             }
         }
     }
     printf ("%d, %d",c, r);
      return 0;
  }
  </code></pre>
  
  <p>The code outputs: 0,0. </p>