#include <stdio.h>
int searchNumber(int arr[], int n, int x);
// printf("");
int main() {
int i, n, store;
printf("Length of array: ");
scanf("%d", & n);
int arr[n];
//Taking the values of the array
for (i = 0; i < n; i++) {
printf("Enter the value of arr[%d]: ", i);
scanf("%d", & arr[i]);
}
//Printing the values
for (i = 0; i < n; i++) {
printf("Value of arr[%d]: %d\n", i, arr[i]);
}
store = searchNumber(arr, n, 5);
printf("%d", store);
return 0;
}
//custom function
int searchNumber(int arr[], int n, int x) {
int left, right, mid;
left = 0;
right = n - 1;
while (left <= right) {
mid = (left + right) / 2;
if (arr[mid] == x) {
return mid;
}
if (x > arr[mid])
left = mid + 1;
else {
right = mid - 1;
}
}
return -1;
}