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