#include <stdio.h>
int searchPage(int pages[], int p){
int start_index=0;
int end_index=49;
while (start_index <= end_index){
int middle = start_index + (end_index- start_index )/2;
if (pages[middle] == p)
return middle;
if (pages[middle] < p)
start_index = middle + 1;
else
end_index = middle - 1;
}
return -1;
}
int main()
{
int pages[49];
int index;
int i;
for(i=0;i<49;i++){
pages[i]=i+1;
}
index=searchPage(pages,11);
if(index!=-1){
printf("\nThe page 11 is present in the book.\n\n");
}else{
printf("\nThe page 11 is NOT present in the book.\n\n");
}
scanf("%d",&i);
return 0;
}
Comments
Leave a comment