For binary search, we have to take an array which is sorted in asending order. If given array is not sorted, then we have to sort it by any sorting technique. After then binary search is possible. It is faster than lenear searching.
#includeint main() { int a[]={10,15,17,20,28,32,40,41,89}; int found,fl=0,min=0,max=8,mid; printf("Enter a number for search : "); scanf("%d",&found); while(min found) { max--; } else { min++; } } if(fl) { printf("%d is found",found); } else { printf("%d is not found",found); } return 0; }
Output:
Enter a number for search : 28
28 is found