0

include<stdio.h>

include<conio.h>

void main(void)

{#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int item,lb=0,ub=9,mid;
int DATA[10]={1,2,3,4,5,6,7,8,9,10};
int beg=lb;int loc;int end=ub;
mid=(beg+end/2);
for(int i=0;i<10;i++)
{
printf("%d",DATA[i]);
printf("\nEnter item");
scanf("%d",item);
while(DATA[mid]!=item &&beg<=end)
{
if(item<DATA[mid])
end=mid-1;
else
beg=mid+1;
}
mid=(beg+end)/2;
}
if(DATA[mid]==item)
{
loc=mid;
else
printf("loc is %d",mid);
else
printf("loc is null");
}
getche();
}
2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by Moschops
0

include<conio.h> Non-standard, very old, not supported by modern compilers.

void main(void) Just plain wrong. C++ recognises int main()

clrscr(); Non-standard, see conio.h

scanf("%d",item); You should be passing a POINTER to item

Your if and else branches are incorrect, missing brackets and that sort of thing.

getche(); Non-standard, see conio.h

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.