title: C array reverse in some range
body: <p>I made a c code.</p>
  
  <pre><code>array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  </code></pre>
  
  <p>and the range can be <code>(0, 3)</code>, <code>(2, 6)</code> etc.</p>
  
  <p>But my code has problem it works some range but some range it didn't work well. I don't know the reason.</p>
  
  <p>This is my code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void reverse(int arr[], int s, int t)
  {
      int i,j, temp;
  
      for (i=s, j=0; i&lt;(t-s)/2 + 1; i++, j++)
      {                       
              temp = arr[i];
              arr[i] = arr[t-j];
              arr[t-j] = temp; 
      }       
  
      for(i = 0; i &lt; 8; i++)
              printf("%d   ", arr[i]);
      printf("\n");
   }
   int main()
   {
      int i, s, t;
  
      printf("start =   ");
      scanf("%d", &amp;s);
      printf("end = ");
      scanf("%d", &amp;t);
  
      int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
  
      reverse(arr, s, t);
  
      return 0;
   }
  </code></pre>
  
  <p>This is correct result.</p>
  
  <p><a href="https://i.stack.imgur.com/kX0hP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kX0hP.png" alt="enter image description here"></a></p>
  
  <p>This is wrong result.</p>
  
  <p><a href="https://i.stack.imgur.com/SpG8S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SpG8S.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/FjgmC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FjgmC.png" alt="enter image description here"></a></p>