Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main(){
- int a[100]={23,29,31,37,42,43,43,65,68,73,76,89,92,99,100,105};
- int start=0,end=16,mid,loc=-1;
- int element=42;
- while(start<=end){
- mid=(start+end)/2;
- if(a[mid]==element){
- loc=mid;
- break;
- }
- else if(a[mid]<element){
- start=mid+1;
- }
- else{
- end=mid-1;
- }
- }
- if(loc==-1){
- printf("Location not Found");
- }
- else{
- printf("Location:%d",loc);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment