-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp11.c
More file actions
48 lines (38 loc) · 759 Bytes
/
exp11.c
File metadata and controls
48 lines (38 loc) · 759 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
48
#include<stdio.h>
int binary(int a[],int start,int end,int element)
{
if(start>end)
return -1;
int mid=(start+end)/2;
if(a[mid]==element)
return mid;
else if(element<a[mid])
binary(a,start,mid-1,element);
else
binary(a,mid+1,end,element);
// return -1;
}
void main()
{
int n,value,pos,i,arr[10];
printf("Enter the total elements in the array : ");
scanf("%d",&n);
int start=0;
int end=n-1;
printf("Enter elements in array\n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter element to search : ");
scanf("%d",&value);
pos=binary(arr,start,end,value);
if(pos!=-1)
{
printf("Element found at %d\n",pos);
}
else
{
printf("Element not found.\n");
}
}