Consider the following C program that attempts to locate an element x in an array Y[ ] using binary search. The program is erroneous.
- f(int Y[10], int x) {
- int u, j, k;
- i = 0; j = 9;
- do {
- k = (i + j)/2;
- if (Y[k] ! = x) && (i < j);
- } while ((Y[k] ! = x) && (i < j));
- if (Y[k] == x) print f(“x is in the array”);
- else print f(“x is not in the array”);
- }
On which of the following contents of Y and x does the program fail?
Reveal answer
Fill a bubble to check yourself
