/*Write a program that will merge the contents of 2 five-element integer arrays namely R and T (previously populated and sorted in ascending order) into an array,Q, in ascending order. Print the content of the array. */ #include #include //declare global arrays int R[5]={1, 4, 5, 6, 10}; int T[5]={2, 3, 5, 8, 17}; int Q[10]; int main() { int rc=0, tc=0, qc=0; while (rc < 5 && tc < 5)//loop through each array until one of them reach their max { if(R[rc] < T[tc]) { Q[qc] = R[rc]; rc++; qc++; } else { if(R[rc] > T[tc]) { Q[qc] = T[tc]; tc++; qc++; } else //R[rc] == T[tc] { Q[qc] = R[rc]; rc++; qc++; Q[qc]= T[tc]; tc++; qc++; } } //prints the remaining values in the other array, if one has already reached its maximum element if (rc == 5) { for(int c = tc; c <= 4; c++) { Q[qc] = T[c]; qc++; } } else { if(tc == 5) { for(int c = rc; c <= 4; c++) { Q[qc] = R[c]; qc++; } } } } //print the array Q for(int c = 0; c <= 9; c++) { printf("%d\n", Q[c]); } getch(); return 0; }