public class BinarySearchExample
public static void Main()
int[] array = { 1, 4, 7, 8, 9, 10, 16, 18, 20, 25 };
Console.Write("Enter the number to search: ");
int target = int.Parse(Console.ReadLine());
int index = BinarySearch(array, target);
Console.WriteLine("found at index");
Console.WriteLine("not found in the array");
public static int BinarySearch(int[] array, int target)
int right = array.Length - 1;
int mid = left + (right - left) / 2;
if (array[mid] == target)