#include <stdio.h> #include <conio.h> main() { int arr[10], num, i, n , pos =-1, beg, end,mid, found =0; clrscr (); printf("\n Enter the number of elements in the array: "); scanf ("%d", &n); printf (" \n Enter the elements: "); for(i=0;i<n;i++) { scanf("%d", &arr[i]); } printf("\n Enter the number that has to be searched: " ); scanf ("%d", &num); beg = 0, end = n-1; while (beg <end) { mid= (beg+ end)/2; if (arr[mid] == num) { printf("\n %dis present in the array at position = %d", num, mid); found=1; break; } if (arr[mid]>num) { end = mid-1; } else if (arr[mid] < num) beg = mid+1; } if ( beg > end &&found == 0) { printf("\n %d DOESNOTEXIST IN THE ARRAY",num); } getch(); return 0; }