title: How do I reverse runs of nonnegative integers in an array in C?
body: <p>I need to create a random array in C, find nonnegative values in it, and when there are at least 2 in a row, reverse them. For example, if I have the random array <code>5 6 -7 -8 9 -4 7 8 2 -2</code> I need to get <code>6 5 -7 -8 9 -4 2 8 7 -2</code>. This is what I've tried so far:</p>
  <pre><code>    #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
   int ARRAY[100];
  int main(void) {
   int i;
   int nn; 
   int temp = ARRAY[i];
   rand();
   
   for (i=0; i&lt;100; ARRAY[i++]=rand()%100-50 );
  
   printf(&quot;FIRST ARRAY:\n&quot;);
   for (i=0; i&lt;100; i++)
      printf(&quot;%3d &quot;,ARRAY[i]);
   putchar('\n');
   putchar('\n');
  
  
  
  for(i=0; i&lt;100; i++){
      if (ARRAY[i]&lt;0) {
          if(!nn) {
              nn = 1;
  
          }
      }
  
          else {
              temp=ARRAY[i];
              ARRAY[i] = ARRAY[nn - 1];
              ARRAY[nn - 1] = temp;
  
  
              }
      }
  
  
  
  
  
  
  
   printf(&quot;Result:\n&quot;);
  
   putchar('\n');
   for (i=0; i&lt;100; printf(&quot;%3d &quot;,ARRAY[i++]));
   putchar('\n');
   return 0;
  }
  </code></pre>
  <p>But had no luck with it.</p>