#include <stdio.h>
#define max 20
int binary(int x,int list[],int n)               /*从list[]中查找x*/
{
    int low,high,mid;
    low=0;
    high=n-1;
    while(low<=high)
    {
        mid=(low+high)/2;               /*折半*/
        if(x<list[mid])                     /*在前半部分查找*/
            high=mid-1;
        else
        if(x>list[mid])                 /*在后半部分查找*/
            low=mid+1;
        else
            return(mid);
    }
    return(-1);
}
int getdata(int list[])                   /*输入数组list[]*/
{
    int num,i;
    printf("total=");
    scanf("%d",&num);
    for(i=0;i<num;i++)
    {
        printf("data[%d]=",i);
        scanf("%d",&list[i]);
    }
    return(num);
}
void main()
{
    int list[max],n,index,x;
    n=getdata(list);
    printf("search key=");              /*输入待查找数据*/
    scanf("%d",&x);
    index=binary(x,list,n);
    if(index>=0)
        printf("data[%d]=%d\n",index,x);
    else
        printf("%d:not found.\n",x);
}