0
use binary searching for found the value from array.but this code doesn't running. what's the problem in this code?
#include<stdio.h> #define arr 15 int main() { int char[arr]={2,7,12,17,22,24,29,34,37,46,51,55,60,61,67}; int location,startpoint,endpoint,midpoint,item; item=60; location=-1; startpoint=0; endpoint=arr-1; while(startpoint<=endpoint) { midpoint=(startpoint+endpoint)/2; if(char[midpoint]==item) { location=midpoint; break; } else if(char[midpoint]<item) startpoint=midpoint+1; else endpoint=midpoint-1; } if(location==-1) printf("%d did not find the number",item); else printf("%d find the number and location is %d",item,location); return 0; }
2 Answers
+ 2
char is a data type did you read the errors?
+ 1
Abhay thanks brother
i caught it