EmbLogic's Blog

Binary search.

head 1.2;
access;
symbols;
locks
root:1.2; strict;
comment @ * @;

1.2
date 2015.02.28.09.26.43; author root; state Exp;
branches;
next 1.1;

1.1
date 2015.02.27.12.00.41; author root; state Exp;
branches;
next ;

desc
@@

1.2
log
@this program is about binary search.
@
text
@#include
#define MAX 4

int main()
{
int l=0;
int h= MAX;
int i;

int key;
int arr[MAX];
printf(“enter the array”);
for(i=0;i<MAX;i++)
{

scanf("%d", &arr[i]);
}
for(i=0;i<MAX;i++)
{
printf("%d=%d:\n", i,arr[i]);
}
printf("enter the key element \n");
scanf("%d", &key);
int m;
while(l<=h)
{
m=(l+h)/2;

if(key==arr[m])
{
printf("key element is found");
break;
}
else if (keyarr[m]&& m<l)
{
l=m+1;
printf("true");
}

else
{
printf("key element is not found");
break;

}

}
return 0;
}

@

1.1
log
@Initial revision
@
text
@d2 2
d6 22
a27 3
int l=0;
int h=9;
int i;
d29 25
a53 32
int key;
int arr[10];
printf("enter the array");
for(i=0;i<10;i++)
{

scanf("%d", &arr[i]);
}
for(i=0;i<10;i++)
{
printf("%d=%d:\n", i,arr[i]);
}
printf("enter the key element \n");
scanf("%d", &key);
while(l<=h)
{
bint m=(l+h)/2;
if(key==arr[m])
{
printf("key element is found");
break;
}
else if(keyarr[m])
l=m+1;

else if(key!=arr[m])

printf(“key element is not found”);
}
return 0;

a54 1

@

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>