Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int key,low=0,high,a[100],n,i,mid,count=0;;
- printf("Enter number of elements\n");count++;
- scanf("%d",&n);count++;
- printf("enter elements in an array\n");count++;
- for(i=0;i<n;i++)
- {
- scanf("%d",&a[i]);count++;
- }
- printf("Enter key\n");count++;
- scanf("%d",&key);count++;
- high=n-1;count++;
- while(low<=high)
- {
- mid=(low+high)/2;count++;
- if(key==a[mid])
- {
- printf("Element is found at position %d\n",mid+1);count++;
- break;count++;
- }
- else if(a[mid]>key)
- { high=mid-1;count++;}
- else
- {low=mid+1;count++;}
- }
- if(low>high)
- printf("element not found\n"); printf("count=%d\n",count);
- getch();
- }
- WHOSE CODE IS THIS??WHO IS THE AUTHOR??
Advertisement
Add Comment
Please, Sign In to add comment