Saturday, December 5, 2009

BINARY SEARCH

Binary search program is one type of searching in data structure.It is used to search the particular name on the given names.

void main()
{
int a[10],n,s,i;
clrscr();
printf("ENTER THE NUMBER OF ELEMENTS:");
scanf("%d",&n);
printf("ENTER THE ELEMENTS:");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("ENTER THE SEARCH ELEMENT:");
scanf("%d",&s);
for(i=1;i<=n;i++)
{
if(s==a[i])
{
printf("SEARCH ELEMENT IS FOUND \n");
printf("THE POSTION OF SEARCH IS");
printf("%d",i);
break;
}
}
if(s!=a[i])
printf("search element is not found");
getch();
}

0 comments:

Post a Comment

  © Blogger template Coozie by Ourblogtemplates.com 2008

Back to TOP