다음 C 프로그램의 실행 결과는?
#include <stdio.h>
int count = 0;
int A[] = {1, 3, 5, 8, 12, 15, 20, 24, 30, 44, 52, 61, 64, 70, 81, 90};
int bin(int low, int high, int key) {
int mid;
count++;
if (low > high) return 0;
else {
mid = (low + high) / 2;
if (key == A[mid]) return 1;
else if (key < A[mid])
return bin(low, mid - 1, key);
else
return bin(mid + 1, high, key);
}
}
int main() {
bin(0, 15, 22);
printf("count: %d, ", count);
bin(0, 15, 52);
printf("count: %d\n", count);
return 0;
}- ①count: 4, count: 8
- ②count: 4, count: 9
- ③count: 5, count: 9
- ④count: 5, count: 10
정답 ③
출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)