Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int a[10]={1,2,3,4,5,6,7,8,9,10};
- int counter;
- int item;
- int beg=0,end=9;
- int mid;
- mid=(beg+end)/2;
- printf("Please enter the element to search: ");
- scanf("%d",&item);
- while(beg<=end && a[mid]!=item){
- if(item>a[mid]){
- beg=mid+1;
- }
- else{
- end=mid-1;
- }
- mid=(beg+end)/2;
- }
- if(a[mid]==item){
- printf("The item %d is found: ",item);
- }
- else{
- printf("The item %d is not found: ",item);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement