title: The values of a 2D matrix is not assigning right
body: <p>I'm a newbie to programming and I'm trying to code to obtain the following pattern</p>
  
  <p>If <code>n=3</code></p>
  
  <pre><code>3 3 3
  3 1 3
  3 2 3
  3 3 3
  </code></pre>
  
  <p>If <code>n=4</code></p>
  
  <pre><code>4 4 4 4 4
  4 4 1 4 4
  4 4 2 4 4
  4 4 3 4 4
  4 4 4 4 4
  </code></pre>
  
  <p>And if <code>n=5</code></p>
  
  <pre><code>5 5 5 5 5
  5 5 1 5 5
  5 5 2 5 5
  5 5 3 5 5
  5 5 4 5 5
  5 5 5 5 5
  </code></pre>
  
  <p>and so on.</p>
  
  <p>My code for the above pattern is below </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main() {
  
    int n, row, col, mid, i, j, mat[50][50], midValue = 1;
    printf("Enter the value of N\n");
    scanf("%d",&amp;n );
    if(n % 2 == 0) {
  
      row = col = n + 1;
  
    }
    else{
  
      col = n;
      row = n + 1;
  
    }
    mid = col / 2;
    printf("%d\n",mid );
    for(i = 0; i &lt; row; i++) {
  
      for(j = 0; j &lt; col; j++) {
  
        if(j == mid &amp;&amp; i != 0) {
  
            mat[row][col] = midValue;
            midValue++;
  
        }
        else {
  
          mat[row][col] = n;
  
        }
  
      }
  
    }
  
    for(i = 0; i &lt; row; i++) {
  
      for(j = 0; j &lt; col; j++) {
  
        printf("%d\t",mat[row][col]);
  
      }
      printf("\n");
  
    }
    return 0;
  
  }
  </code></pre>
  
  <p>But, all my matrix elements are just set to the value of N. I couldn't figure where I've gone wrong. Can anyone point out the mistake?</p>