I have one array of elements with **1 5 9 (e.g. a1 a2 a3)**  

and second array of elements with **2 4 8 (e.g. b1 b2 b3)**

I want the output to be **1,2 5,4 9,8 (i.e. a1,b1 a2,b2 a3,b3)**... Is it possible?
All the loops I tried sort the entire thing like 1,2,4,5,8,9?

Code block:

```
void merge(int a[], int m, int b[], int n, int sorted[]) {
  int i, j, k;

  j = k = 0;

  for (i = 0; i < m + n;) {
     if (j < m && k < n) {
        if (a[j] < b[k]) {
          sorted[i] = a[j];
          j++;
        }
        else {
          sorted[i] = b[k];
          k++;
        }
        i++;
     }
     else if (j == m) {
        for (; i < m + n;) {
          sorted[i] = b[k];
          k++;
          i++;
        }
     }
     else {
        for (; i < m + n;) {
          sorted[i] = a[j];
          j++;
          i++;
        }
     }
  }
}

```