Periyasamy Vellingirisamy
Write a program to find an number in array of integers using Binary Search using c#

Program to find a number in a array using binary search without using build in functions.

By Periyasamy Vellingirisamy in C# on Jun 01 2020
  • Periyasamy Vellingirisamy
    Jul, 2020 3

    Hi
    Refer below program.

    1. int[] arr = { 23, 56, 67, 78, 89, 90, 94, 95, 96, 97, 99 };
    2. int key = 97;
    3. int minNum = 0;
    4. int maxNum = arr.Length - 1;
    5. while (minNum <= maxNum)
    6. {
    7. int mid = (minNum + maxNum) / 2;
    8. if (key == arr[mid])
    9. {
    10. ++mid;
    11. break;
    12. }
    13. else if (key<arr[mid])
    14. {
    15. maxNum = mid - 1;
    16. }
    17. else
    18. {
    19. minNum = mid + 1;
    20. }
    21. }

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS