title: Mergesort implementation in C
body: <p>Can someone please check my mergesort code. When I tried sorting the input values, the sorted array contained random values which weren't from input. And they were not sorted.
  Is the way I'm declaring array within the while loop correct?</p>
  
  <pre><code>  #include &lt;stdio.h&gt;
  void merge (int a[], int aux[], int lo, int mid, int hi){
  
      for(int y=lo; y&lt;=hi; y++){
          aux[y]=a[y];
      }
      int i=lo; 
      int j=mid+1;
      for(int k=lo;k&lt;=mid;k++){
          if (j&gt;hi)           a[k]=aux[i++];
          else if (i&gt;mid)     a[k]=aux[j++];
          else if (a[j]&lt;a[i])
          a[k]= aux[j++];
          else
          a[k]=aux[i++];
      }
  return;
  }
  
  
  void sort (int b[],int aux[], int lo, int hi)
  { 
  
  if(hi&lt;=lo)
  return;
  int mid= lo+(hi-lo)/2;
  sort(b, aux, mid+1, hi);
  sort(b, aux, lo,  mid);
  merge(b,aux,lo,mid,hi);
      return;
  }
  
  
  
  int main(void) {
  
  int t,n;
  
  long long int sum;
  scanf("%d",&amp;t);
  while(t--){
      sum=0;
      scanf("%d",&amp;n);
      int w[n];
      int m[n];
      int g[n];
      int h[n];
      for (int i=0; i&lt;n;i++){
          scanf("%d",&amp;m[i]);
          }
  
  
      for (int j=0; j&lt;n;j++){
          scanf("%d",&amp;w[j]);
  }   
  
  
      sort(w,g,0,n-1);
      sort(m,h,0,n-1);
  
  }
      return 0;
  }
  </code></pre>