-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursivebinarysearch.c
More file actions
40 lines (37 loc) · 872 Bytes
/
Recursivebinarysearch.c
File metadata and controls
40 lines (37 loc) · 872 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
#include<stdio.h>
#include<conio.h>
#include<stdbool.h>
bool isfind(int arr[], int size, int key){
int low = 0, high = size - 1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == key) {
return true;
}
else if (arr[mid] < key) {
low = mid + 1;
}
else {
high = mid - 1;
}
}
return false;
}
int main(){
int arr[10];
printf("Enter elements of array in non decreasing order: ");
for(int i=0; i<10; i++){
scanf("%d", &arr[i]);
}
int key;
printf("Enter the element which yo want to search: ");
scanf("%d", &key);
if(isfind(arr, 10, key)){
printf("%d is found.", key);
}
else{
printf("%d is not found.", key);
}
return 0;
getch();
}