Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Binary search
- #include<stdio.h>
- int main()
- {
- int arr[12] = {12,23,30,32,38,42,50,60,65,70,85,90,100};
- int start,end,mid,key;
- start=0;
- end=12;
- key = 32;
- do{
- mid = (start+end)/2;
- if(arr[mid] == key)
- {
- printf("Value is found at %dth position\n",mid+1);
- break;
- }
- else if(arr[mid] > key)
- {
- end = mid-1;
- }
- else
- {
- start = mid+1;
- }
- }
- while(start <= end);
- if(start>end)
- {
- printf("failed");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement