#include<stdio.h>
void Search(int a[],int n,int x,int*i,int*j){
     int start=0,end=n-1;
     *i=-1;
	 *j=-1;
     while(start<end){
       	 int mid=start+(end-start)/2;
	      if(a[mid]==x){
		    *i=mid;
		    *j=mid;
	      }
	      else if(a[mid]<x){
	  	       start=mid+1;
		       *i=mid;
	      }
	      else {
		     end=mid-1;
	         *j=mid;
	      }
     }
}
int main(){
	int a[]={2,4,6,8,9,10,12,13};
	int x=8;
	int n=sizeof(a)/sizeof(a[0]);
	int i,j;
	 Search(a,n,x,&i,&j);
	if(i==-1&&j==-1){
		printf("未找到%d的信息\n",x);
	}
	else if(i==j){
		printf("目标元素%d位于%d\n",x,i);
	}
	else{
		printf("未找到目标元素%d的值\n",x);
		printf("小于%d的最大元素位置%d\n",x,i);
		printf("大于%d的最小元素位置%d\n",x,j);
	} 
}

