#include
#include
void main()
{
int a[10],i,n,mid,high,low,count=0,n1;
clrscr();
printf("\nEnter the num of elements in the array:");
scanf("%d",&n);
printf("\nEnter the elements into the array");
flushall();
for(i=0;i
printf("\nEnter the number to be searched in the list:");
scanf("%d",&n1);
low=a[0];
high=a[n-1];
mid=(low+high)/2;
while(1)
{
if(mid==n1)
{
count++;
break;
}
else if(mid>n1)
{
high=mid-1;
}
else if(mid
low=mid+1;
}
if(low>=high)
break;
// else if((mid==high)||(mid==low))
// break;
mid=(high+low)/2;
}
if(count==0)
printf("\nThe number %d is in not in given list",n1);
else
printf("\nThe number %d is in given list",n1);
getch();
}
No comments:
Post a Comment