#include <stdio.h>
int binarySearch(int arr[], int n, int key) { int low = 0, high = n - 1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] == key) { return mid; } else if (arr[mid] < key) { low = mid + 1; } else { high = mid - 1; } } return -1; // key not found }
int main() { int arr[] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; int n = sizeof(arr) / sizeof(arr[0]); int key = 12; int index = binarySearch(arr, n, key); if (index != -1) { printf(“Element %d found at index %d”, key, index); } else { printf(“Element not found”); } return 0; }