#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n = 5, m = 7;
int A[] = {1, 3, 5, 7, 9};
int B[] = {2, 4, 6, 8, 10, 12, 14};
int C[n+m];
int i = 0, j = 0, k = 0;
while (i < n && j < m) {
if (A[i] < B[j]) {
C[k] = A[i];
i++;
} else {
C[k] = B[j];
j++;
}
k++;
while (i < n) {
while (j < m) {
for (int i = 0; i < n + m; i++) {
cout << C[i] << " ";
cout << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n = 5, m = 7;
int A[] = {1, 3, 5, 7, 9};
int B[] = {2, 4, 6, 8, 10, 12, 14};
int C[n+m];
int i = 0, j = 0, k = 0;
while (i < n && j < m) {
if (A[i] < B[j]) {
C[k] = A[i];
i++;
} else {
C[k] = B[j];
j++;
}
k++;
}
while (i < n) {
C[k] = A[i];
i++;
k++;
}
while (j < m) {
C[k] = B[j];
j++;
k++;
}
for (int i = 0; i < n + m; i++) {
cout << C[i] << " ";
}
cout << endl;
return 0;
}