Advertisement
shawonrog

Untitled

Sep 26th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int beg=0,end,data[30],i,loc,item,mid;
  5. printf("Enter Data Langth\n");
  6. scanf("%d",&end);
  7. printf("Enter Data\n");
  8. for(i=0;i<end;i++)
  9. {
  10. scanf("%d",&data[i]);
  11. }
  12. mid=(int)(beg+end)/2;
  13. printf("Enter Item\n");
  14. scanf("%d",&item);
  15. while(beg<end && data[mid]!=item)
  16. {
  17. if(item<data[mid])
  18. {
  19. end = mid-1;
  20. }
  21. else
  22. {
  23. beg = mid+1;
  24. }
  25. mid++;
  26.  
  27. }
  28. if(data[mid]==item)
  29. {
  30. loc = mid;
  31.  
  32. }
  33. else
  34. {
  35. loc= 0;
  36.  
  37. }
  38. printf("Found Loc at = %d",loc);
  39.  
  40.  
  41. return 0;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement