#include "conio.h"
void main ()
{
int LA[6]={2,4,6,8,10,12},i,j,beg=0,mid,end=5;
clrscr ();
mid=((beg+end)/2);
printf("2,4,6,8,10,12\n\n");
printf ("Entr the number to be searched: ");
scanf ("%d",&j);
for (;beg<=end && j!=LA[mid];)
{
if (j
end=mid-1;
else
beg=mid+1;
mid=((beg+end)/2);
}
if (LA[mid]==j)
printf ("The location is: %d",(mid+1));
else
printf ("The location does not exist!");
getch ();
}
0 comments:
Post a Comment