Search unanswered questions...
Enter a question here...

Binary search program in c using for loop?

[Edit]

C PROGRAM FOR BINARY SEARCH

void main()
{
int a[10],i,n,m,c,l,u;
clrscr();
printf("Enter the size of an array->");
scanf("%d",&n);
printf("\nEnter the elements of the array->");
for(i=0;i
{
scanf("%d",&a[i]);
}
printf("\nThe elements of an array are->");
for(i=0;i
{
printf(" %d",a[i]);
}
printf("\nEnter the number to be search->");
scanf("%d",&m);
l=0,u=n-1;
c=binary(a,n,m,l,u);
if(c==0)
printf("\nThe number is not in the list");
else
printf("\nThe number is found");
getch();
}
int binary(int a[],int n,int m,int l,int u)
{
int mid,c=0;
if(l<=u)
{
mid=(l+u)/2;
if(m==a[mid])
{
c=1;
}
else
if(m
{
return binary(a,n,m,l,mid-1);
}
else
return binary(a,n,m,mid+1,u);
}
else
return c;
}

Improve Answer Discuss the question "Binary search program in c using for loop?" Watch Question

First answer by ID3411788082. Last edit by ID3411788082. Question popularity: 1 [recommend question]

Research your answer:

Answers.com > Wiki Answers > Categories > Technology > Computers > Computer Programming > Binary search program in c using for loop?

Our contributors said this page should be displayed for the questions below. (Where do these come from)
If any of these are not a genuine rephrasing of the question, please help out and edit these alternates.
C program for binary search?  Binary search programme in c?  Program for binary searching?  Program to linear search in c?  Binary search program in java?  7 Write a Binary Search program?  Program to Linear search using c?  What are the drawbacks of binary search?  Lenear search program in cusing for loop?  Write a program in 'c' language to merge the contents of two binary search trees into one?