Join Our Email Alerts-Subscribe
Important Note:Login & Check Your Email Inbox and Activate Confirmation Link



Enter Your Email :


Programming Souce Codes & ebooks-Free Download

Free ebooks

Programming Study Materials & ebooks

Online Training


C Program For BINARY SEARCH.

void main()

{

int n,i,search,f=0,low,high,mid,a[20];

clrscr();

printf("Enter the n value:");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

printf("Enter the number in ascending order a[%d]=",i);

scanf("%d",&a[i]);

}

printf("Enter the search element:");

scanf("%d",&search);

low=1;

high=n;

while(low<=high)

{

mid=(low+high)/2;

if(search
{

high=mid-1;

}

else if(search>a[mid])

{

low=mid+1;

}

else

{

f=1;

printf("obtainedin the position %d:",mid);

getch();

exit();

}

}

if(f==0)

{

printf("not present");

}

getch();

}


All Programming Codes/Onlie Training/ Lab Manuals Download