Showing posts with label SEARCHING OF THE ELEMENTS OF BINARY NUMBER. Show all posts
Showing posts with label SEARCHING OF THE ELEMENTS OF BINARY NUMBER. Show all posts

SEARCHING OF THE ELEMENTS OF BINARY NUMBER

main()
{
int a[100],i,n,j,search,mid,temp;
printf("\n how many no's in array");
scanf("%d",&n);
printf("\n enter %d elements in array",n);
for(i=0;i
scanf("%d",&a[i]);
for(i=0;i
{
for(j=i+1;j
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
printf("%4d",a[i]);
}
printf("\n enter search element");
scanf("%d",&search);
mid=n/2;
if(a[mid]==search)
{
printf("\n location of searched element %d ",mid);
}
if(search>a[mid])
{
for(i=mid+1;i
{
if(a[i]==search)
{
printf("\n location of sarched element is %d",i);
}
else
for(i=0;i
{
if(a[i]==search)
printf("\n location of searched element %d",i+1);
}xc
getch();
}
}
}

Labels