i have some output errors,if know thathelp me

October 6, 2010 at 08:11:18
Specs: Windows XP
/*-----------BINARY SEARCHING---------------*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,a[20],s,c,loc,mid,beg,end,t;
char d;
clrscr();
printf("\n\t\t\tBINARY SEARCH");
printf("\n\t\t\t~~~~~~~~~~~~~~");
printf("\n Enter the number of elements:");
scanf("%d",&n);
printf("\n Enter the element:\n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("\n The sorted array is:\n");
for(i=0;i<=n;i++)
{
printf("\t%d",a[i]);
}
printf("\n\t Enter the demand to be searched:");
scanf("%d",&s);
beg=1;
end=n;
mid=(beg+end)/2;
while((beg<end)&&(a[mid]!=s))
{
if(s<a[mid])
end=mid-1;
else
end=mid+1;
mid=(beg+end)/2;
}
if(a[mid]==s)
{
loc=mid;
printf("\n\t Element found:\n");
printf("\n\t Item=%d",a[mid]);
printf("\n\t Location=%d",loc);
}
else
printf("\nELEMENT NOT FOUND!");
getch();
}

See More: i have some output errors,if know thathelp me

Report •

#1
October 6, 2010 at 20:35:23
WOW! That's all GREEK to me. What exactly are you asking?

Some HELP in posting on Computing.net plus free progs and instructions Cheers


Report •
Related Solutions


Ask Question