title: C language 2d array fill diagonal with numbers from 1 to n
body: <p>I have a 2d array filled with 0's and i'm trying to fill the main diagonal with numbers from 1 to n, this is the main code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
      
  int main()
  {
      srand(time(NULL));
      int m, n, i, j;
      printf(&quot;Number of rows and columns:&quot;);
      scanf(&quot;%d&quot;, &amp;n);
      int a[n][n];
      for (i = 0; i &lt; n; i++)
          for(j = 0; j &lt; n; j++)
              a[i][j] = rand() % 1;
      printf(&quot;The matrix is:\n&quot;);
      for (i = 0; i &lt; n; i++)
      {
          printf(&quot; \n &quot;);
          for(j = 0; j &lt; n; j++)
          {
              printf(&quot; %d\t &quot;, a[i][j]);
          }
      }
  } 
  </code></pre>
  <p>What I've tried to do is to fill the diagonal manually, but that's not what I want to do. I want to make it fill itself automatically. I need to do it without using any functions.</p>