#include <stdio.h>
int main()
{
int c, a, b, y, n, search, array[100];
printf("Enter number of elements to be printed :\t");
scanf("%d",&n);
printf("Enter %d integers : \t", n);
for (c = 0; c < n; c++)
scanf("%d",&array[c]);
printf("Enter value to find : \t ");
scanf("%d", &search);
a = 0;
b = n - 1;
y = (a+b)/2;
while (a <= b) {
if (array[y] < search)
a = y + 1;
else if (array[y] == search) {
printf("%d found at location %d.\n", search, y+1);
break;
}
else
b = y - 1;
y = (a + b)/2;
}
if (a > b)
printf("Not found! %d is not present in the above list.\n", search);
return 0;
}
OUTPUT : -
Follow
Me On Social Media :-
INSTA photography page :- https://www.instagram.com/photo_mania_hub/
Twitter link : - https://twitter.com/ApurbaKhanra199
Facebook page link (Crazy Coders) :-https://www.facebook.com/codercrazy/?modal=admin_todo_tour
Insta photography link :- https://www.instagram.com/photo_mania_hub/
Facebook link :- https://www.facebook.com/profile.php?id=100009747586288
For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/
0 Comments