#include<stdio.h>
#include<conio.h>
#define SIZE 10
int found=0;
int binarysearch(int [],int);
void main()
{
int list[SIZE]={22,36,45,65,59,48,21,54,77,91};
int target,res;
clrscr();
printf("\n\t enter target:");
scanf("%d",&target);
res=binarysearch(list,target);
if(found)
printf("\n\t the target is found at location:%d",res);
else
printf("\n\t the target is not found");
getch();
}
int binarysearch(int list[],int target)
{
int low,mid,high;
low=0;
high=SIZE;
while(low<=high)
{
mid=(low+high)/2;
if(target<list[mid])
high=mid-1;
else
if(target>list[mid])
low=mid+1;
else
{
found=1;
break;
}
}
return(mid);
}
#include<conio.h>
#define SIZE 10
int found=0;
int binarysearch(int [],int);
void main()
{
int list[SIZE]={22,36,45,65,59,48,21,54,77,91};
int target,res;
clrscr();
printf("\n\t enter target:");
scanf("%d",&target);
res=binarysearch(list,target);
if(found)
printf("\n\t the target is found at location:%d",res);
else
printf("\n\t the target is not found");
getch();
}
int binarysearch(int list[],int target)
{
int low,mid,high;
low=0;
high=SIZE;
while(low<=high)
{
mid=(low+high)/2;
if(target<list[mid])
high=mid-1;
else
if(target>list[mid])
low=mid+1;
else
{
found=1;
break;
}
}
return(mid);
}