Question
#include <iostream>
using namespace std;
int A[5] = {1, 3, 5, 6, 18};
int B[5] = {2, 4, 7, 11, 16};
int C[10];
int main() {
int i = 0, j = 0, k = 0;
while (i < 5 || j < 5) {
if (A[i] <= B[j]) {
C[k] = A[i];
i++; k++;
} else {
C[k] = B[j];
j++; k++;
}
}
if (i > j) {
while (i < 5) {
C[k] = A[i];
i++; k++;
}
} else {
while (j < 5) {
C[k] = B[j];
j++; k++;
}
}
for (int l = 0; l < 10; l++) {
cout << C[l] << " ";
}
cout << endl;
return 0;
}
Program ini seharusnya menggabungkan dua array terurut menjadi satu array terurut. Namun terdapat bug sebanyak dua baris sehingga output keliru. Pada baris ke berapa sajakah bug tersebut berada?
Jawab: …………………………………………………… {tuliskan dua nomor baris terurut menaik}