title: how to print an array in c according to if they are ascending and descending in different lines?
body: <p>I am trying to print the elements of an array in different lines according to if they are ascending or descending. for example I have an array: 
  a[] = {3,5,6,8,4,2,-1,-3,6,5,4,1,3}; after I call the method printArr(a, sizeof(a), indexStart); the output should be:</p>
  
  <pre><code>3568
  842-1-3
  -36
  6541
  13
  </code></pre>
  
  <p>here is my code:</p>
  
  <pre><code>void printArr(int *a, int size, int index){
  int i=index;
  if(i==size)
      return;
  printf("%d",a[i]);
  if(a[i]&lt;a[i+1]){
      while(a[i]&lt;a[i+1] &amp;&amp; i&lt;size){
          printf("%d",a[i+1]);
          i++;
      }
      printf("\n");
  }
  else{
      while(a[i]&gt;a[i+1] &amp;&amp; i&lt;size){
          printf("%d",a[i+1]);
          i++;
      }
      printf("\n");
  }
  printArr(a,size,i);
  }
  </code></pre>
  
  <p>here is my main:</p>
  
  <pre><code>int main()
  {
  int a[] = {3,5,6,8,4,2,-1,-3,6,5,4,1,3};
  printArr(a,13,0);
  return 0;
  }
  </code></pre>
  
  <p>when I run it (CodeBolcks) I get the following input:</p>
  
  <pre><code>3568
  842-1-3
  -36
  6541
  1370
  </code></pre>
  
  <p>where did the 70 at the end come from? 
  when I compile it in Linux(terminal) I get the following :</p>
  
  <pre><code>3568
  842-1-3
  -36
  6541
  1332767
  </code></pre>
  
  <p>where did the 32767 at the end come from? how can I fix my code? 
  I have to use loops and recursion.</p>