Sie sind auf Seite 1von 2

#include<stdio.

h>
#include<conio.h>
void main()
{
int n,a[10],i,sele,first,last,mid;
clrscr();
printf("enter array length\n");
scanf("%d",&n);
printf("enter array elements in ascending order\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter search element\n");
scanf("%d",&sele);
first=0;
last=n-1;
while(first<=last)
{
mid=(first+last)/2;
if(a[mid]==sele)
{
printf("%d element is found %d\n",sele,mid+1);
exit(0);
}
if(sele<a[mid])
last=mid-1;
else
first=mid+1;
}
printf("element is not found in the array\n");
getch();
}

Das könnte Ihnen auch gefallen