title: Binary search issue in c
body: <p>If i entered  the 4th index element in x it runs correctly, if i entered other elements in the array it returns -1</p>
  <pre><code>#include&lt;stdio.h&gt;
  
  int Binary_search(int A[],int n,int x)
  {
      int start=0,end = n-1;
      while(start&lt;=end)
      {
          int mid = (start+end)/2;
          if(x == A[mid])return mid;
          else if(x &lt; A[mid]) end = mid-1; 
          else start = mid+1;
      }
      return -1;
  }
  
  int main()
  {
      int A[] = {3,23,26,51,72,77,42,64};
      puts(&quot;Enter the element &quot;);
      int x; scanf(&quot;%d&quot;,&amp;x);
      int len = sizeof(A)/sizeof(A[0]);
      int index = Binary_search(A,len,x);
      if(index != -1) printf(&quot;Number %i is at index %i&quot;,x,index);
      else printf(&quot;It's not in the array&quot;);
  }
  </code></pre>