---
# System prepended metadata

title: C語言題庫-064

---

# C語言題庫-064
寫出二分查找的代碼。
【參考答案】 
```
int b inary_search(int* arr, int k ey, int n)
{
int low = 0;
int h igh = n - 1 ;
int m id;
while (low <= high)
{
mid = (high + low) / 2;
if (arr[mid] > k)
high = mid -1 ;
else if (arr[mid] < k)
low = mid + 1;
else
return mid;
}
return -1;
}
```

