考慮下面的 C 語言程式,該程式嘗試在陣列(array)Y[]中找到元素 x。不過該程式是錯誤的,請問程式在哪一個選項情況下執行會出問題?
f(int Y[10], int x) {
int i, j, k;
i = 0; j = 9;
do {
k = (i + j) / 2;
if(Y[k] < x) i = k; else j = k;
} while(Y[k] != x && i < j);
if(Y[k] == x) printf("x is in the array");
else printf("x is not in the array");
AY 為[1 2 3 4 5 6 7 8 9 10]且 x < 10
BY 為[1 3 5 7 9 11 13 15 17 19]且 x < 1
CY 為[2 2 2 2 2 2 2 2 2]且 x > 2正確答案
DY 為[2 4 6 8 10 12 14 16 18 20] 且 $2 < x < 20$ 且 $x$ 是偶數