Program to do binary search of element in C
Program to do binary search of element in C
What is searching ?It is defined as find data of a element. We use different types of searching techniques for searching an element.
Here we use binary search techniques in C.
Program to do binary search of element in C
#include<conio.h>
void main ()
{
int data[10],beg,mid,end,item,lb,ub,i;
clrscr ();
printf ("\n Enter 5 element in selected order:");
scanf ("%d", &item);
beg=0;
end=4;
mid=(beg+end)/2;
while(beg<=end && data[mid]!=item)
{
if (item>data[mid])
{
beg=mid+1;
}
else
{
end=mid-1;
}
mid=(beg+end)/2;
}
if(beg<end)
{
printf("\n location = %d",mid+1);
}
else
{
printf("\n unsuccessful:");
}
getch ();
}
OUTPUT :: Enter 5 element in selected order = 25,45,65,75,85
ITEM SEARCHED ; 45
Comments
Post a Comment
Thank You for your participation..