DFS :: BINARY

/***************************************************************************
ROLL NO : 93
CLASS : SYBCA
SUBJECT : DFS
DIVISION : II
PROGRAM : BINARY SEARCH
***************************************************************************/
# include <stdio.h>
# include <conio.h>
void main()
{
int k[10],x,low,high,mid,i;
clrscr();
for (i=0;i<=9;i++)
{
printf(“\n Enter element no %d:”,i+1);
scanf(“%d”,&k[i]);
low=0;
high=9;
}
printf(“Enter the no”);
scanf(“%d”,&x);

while(low<=high)
{
mid=(low+high)/2;
if(k[mid]==x)
{
printf(“found”);
break;
}
if(k[mid]>x)
{
high=mid-1;
}
else
low=mid+1;
}
if(low>high)
printf(“not found”);
getch();
}

/***************************************************************************
OUTPUT:-

Enter element no 1:5

Enter element no 2:6

Enter element no 3:7

Enter element no 4:8

Enter element no 5:9

Enter element no 6:10

Enter element no 7:1

Enter element no 8:2

Enter element no 9:3

Enter element no 10:4
Enter the no:5
found
***************************************************************************/

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.