#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],lb,ub,mid,i,key,n;
clrscr();
printf("Enter the no. of element in the array \n");
scanf("%d",&n);
printf("enter the array elements \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the key element to search \n");
scanf("%d",&key);
lb=0;
ub=n-1;
mid=(lb+ub)/2;
while(lb<=ub&a[mid]!=key)
{
if(key<a[mid])
ub=mid-1;
else
lb=mid+1;
mid=(lb+ub)/2;
}
if(a[mid]==key)
{
printf("element is found");
}
else
{
printf("element is not found");
}
getch();
}
OUTPUT:-

#include<conio.h>
void main()
{
int a[10],lb,ub,mid,i,key,n;
clrscr();
printf("Enter the no. of element in the array \n");
scanf("%d",&n);
printf("enter the array elements \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the key element to search \n");
scanf("%d",&key);
lb=0;
ub=n-1;
mid=(lb+ub)/2;
while(lb<=ub&a[mid]!=key)
{
if(key<a[mid])
ub=mid-1;
else
lb=mid+1;
mid=(lb+ub)/2;
}
if(a[mid]==key)
{
printf("element is found");
}
else
{
printf("element is not found");
}
getch();
}
OUTPUT:-
I am certain this article has touched all the web visitors; it’s very extremely lovely script.
ReplyDeletetutorial for c++