Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int a[100010] ;
- int main()
- {
- int mid,beg,end,key,n,i;
- scanf("%d",&n);
- for(i=1;i<=n;i++)
- {
- scanf("%d",&a[i]);
- }
- scanf("%d",&key);
- beg=1;
- end=n;
- int res ;
- while(beg<=end)
- {
- mid= (beg+end)/2;
- if(a[mid]==key)
- {
- res = mid ;
- break;
- }
- else if(a[mid]<key)
- {
- beg=mid+1;
- }
- else if(a[mid]>key)
- {
- end=mid-1;
- }
- }
- printf("%d\n",res) ;
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement