//binary search
#include "stdio.h"
int search (int a[],int n,int x);
void main()
{
int i,x,z;
int a[10];
printf("Please inpur tne numbers:\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("Please input the number you want tosearch: \n");
scanf("%d",&x);
z=search(a,10,x);
if(z)
printf("the position of number %d you want to search is: %d\n",x,z);
else printf("No this number %d in the array!\n",x);
} //Function of Binary search;
int search(int a[],int n,int x)
{
int low,mid,high;
low=0;
high =n-1;
while(low<=high) //when low==high ..it means that there is no number in it
{
mid=(low+high)/2;
if(xa[mid]) low=mid;
else return mid;
}
return 0;
}