#include<stdio.h>
#include<conio.h>
seq_search()
{
int a[10],i,k;
printf("please input ten number");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("please input the key for search");
scanf("%d",&k);
for(i=0;i<10;i++)
{
if(a[i]==k)
{printf("sucess!the number is %d",i+1);
return(0);}
printf("failure");
return(0);}}
half_search()
{
int mid,low,high;
int b[10],m,key,h;
printf("please input ten number:");
for(m=0;m<10;m++)
scanf("%d",&b[m]);
printf("please input the key for search:");
scanf("%d",&h);
low=0;
high=9;
while(low<=high)
{mid=(low+high)/2;
if(b[mid]>h) high=mid-1;
else {if(b[mid]<h) low=mid+1;
else {printf("sucess!");
return(0);}
}
}
printf("failure!");
}
main()
{
int a[10],k,i;
clrscr();
printf("1.seq_search;");
printf("2.half_search;");
printf("please input your choice:1 or 2");
scanf("%d",&i);
if(i==1) seq_search();
else half_search();
}