-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary.c
More file actions
47 lines (47 loc) · 894 Bytes
/
Copy pathbinary.c
File metadata and controls
47 lines (47 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
void main()
{
int a[50],n,i,choice,swap,j,l,r,m;
printf("enter limit");
scanf("%d",&n);
printf("enter %d elements",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
swap=a[j];
a[j]=a[j+1];
a[j+1]=a[j];
}
}
}
printf("enter the element to be searched");
scanf("%d",&choice);
l=0;
r=n-1;
m=(l+r)/2;
while(l<=r)
{
if(a[m]<choice)
{
l=m+1;
}
else if(a[m]==choice)
{
printf("found at index %d",m+1);
}
else
{
r=m-1;
m=(l+r)/2;
}
}
if(l>r)
{
printf("not found!!");
}
}