title: How to make a spiral array?
body: <p>I am trying to make a spiral that looks like this:</p>
  <pre class="lang-none prettyprint-override"><code>21  22  23  24  25
  20   7   8   9  10
  19   6   1   2  11
  18   5   4   3  12
  17  16  15  14  13
  </code></pre>
  <p>But I can't start from the center.<br />
  What needs to be changed?<br />
  I don't know how to tune my loops.<br />
  The task was that I would start from the number that was given in the console and after that, in the form of a snail, the program produced this picture.<br />
  I have some ideas about middle int this array but it's not work.</p>
  <p>Description: User input number 1, 2, 3.....
  Program should output spiral array like this</p>
  <p>I am try, but dont understand how to make it. My program print spiral array but not started in a middle array.</p>
  <p>First i am find dimension array, after I find the numbers and put them in the array
  but it doesn't work like that
  My code:</p>
  <pre><code>int m = int.Parse(Console.ReadLine());
  int counter = 0;
  // find size our matrix
  for (int i = 1; i &lt; m; i++)
  {
      counter = i * i;
  
      if (counter &gt;= m)
      {
          counter = i;
          break;
      }
  }
  
  Console.WriteLine(counter);
  
  int[,] arr2 = new int[counter, counter];
  
  // add zero in array 
  for (int i = 0; i &lt; counter; i++)
  {
      for (int j = 0; j &lt; counter; j++)
      {
          arr2[i, j] = 0;
      }
  }
  Console.WriteLine();
  
  int count = 1;
  int a = 0;
  int midlle = counter - 2;
  
  while (arr2[a, a] == 0)
  {
      if (arr2[a, a] == 0)
      {
          
          for (int i = midlle; i &lt;= midlle; i++)
          {
              for (int j = midlle; j &lt; counter - midlle; j++)
              {
                  arr2[i, j] = count;
                  count++;
              }
          }
  
          for (int i = 1 + midlle; i &lt; counter - midlle; i++)
          {
              for (int j = (counter - 1) - midlle; j == (counter - 1) - midlle; j++)
              {
                  arr2[i, j] = count;
                  count++;
              }
          }
  
          for (int i = (counter - 1) - midlle; i == (counter - 1) - midlle; i++)
          {
              for (int j = (counter - 2) - midlle; j &gt;= 0 + midlle; j--)
              {
                  arr2[i, j] = count;
                  count++;
              }
          }
  
          for (int i = (counter - 2) - midlle; i &gt; 0 + midlle; i--)
          {
              for (int j = 0 + midlle; j == 0 + midlle; j++)
              {
                  arr2[i, j] = count;
                  count++;
              }
          }
          a++;
  
      }
  }
  
  
  // add sticks and final result 
  for (int i = 0; i &lt; counter; i++)
  {
      for (int j = 0; j &lt; counter; j++)
      {
          Console.Write(arr2[i, j] + &quot;|&quot;);
      }
      Console.WriteLine();
  }
  </code></pre>