DFS :: BINSEARCH

#include<iostream.h>
#include<conio.h>

search(int s,int e,int *a,int x)
{
int m;
m=(s+e)/2;

if(x==a[m])
{
cout<<“Found.”;
}
else
if(x<a[m])
{
search(s,m-1,a,x);
}
else if(x>a[m])
{
search(m+1,e,a,x);
}
}
void main()
{
int a[5],i,x;
clrscr();

for(i=0;i<5;i++)
{
cout<<“enter the value: “;
cin>>a[i];
}

cout<<“Enter the value to be searched: “;
cin>>x ;

search(0,4,a,x);

getch();
}

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.