#include<stdio.h>
#include<conio.h>
void main()
{
int low=1,mid,high,n=10,k[10],i,x;
clrscr();
for(i=1;i<=n;i++)
{
printf("\nEnter value:-");
scanf("%d",&k[i]);
}
printf("\n\n\t\tEnter value of you want to search:-");
scanf("%d",&x);
high=n;
while(low<=high)
{
mid=(high+low)/2;
if(x==k[mid])
{
printf("\n\nsuccessful search");
getch();
return;
}
else
{
if(x>k[mid])
{
low=mid+1;
}
else
{
high=mid-1;
}
}
}
printf("\n\n\t\tUnsuccessful search");
getch();
}
#include<conio.h>
void main()
{
int low=1,mid,high,n=10,k[10],i,x;
clrscr();
for(i=1;i<=n;i++)
{
printf("\nEnter value:-");
scanf("%d",&k[i]);
}
printf("\n\n\t\tEnter value of you want to search:-");
scanf("%d",&x);
high=n;
while(low<=high)
{
mid=(high+low)/2;
if(x==k[mid])
{
printf("\n\nsuccessful search");
getch();
return;
}
else
{
if(x>k[mid])
{
low=mid+1;
}
else
{
high=mid-1;
}
}
}
printf("\n\n\t\tUnsuccessful search");
getch();
}
No comments:
Post a Comment