/*bi means two therefore the array which use in the program we reduce it size into two
parts
Binary search proess is use for large array mean that search involve to hindel the large
number of array */
#include <iostream>
#include <conio>
/*****************************************/
void main()
{
int arr[10];
int s,e,n,i,m,loc;
loc=1;
cout<<"Enter numbers into Array\n";
for(i=0;i<10;i++)
{
cin>>arr[i];
}
cout<<"Enter any number\t:";cin>>n;
cout<<endl;
e=10;
for(s=0;s<=e;s++)
{
m=(s+e)/2;
if(n==arr[m])
{loc=m+1;
break;
}
else
{
if(n<arr[m])
{ e=m-1; }
else
{s=m+1 ; } }
}
if(loc==0)
cout<<"Value not founded\n" ;
else
cout<<"Value founded at position\t"<<loc<<endl;
getch();}
0 comments:
Post a Comment