title: Binary search in C using recursive function with return type
body: <p>Here below, I am trying to write a simple binary search program using recursive function. When I run it, It takes the array and key to be searched as input but after that the compiler stops abruptly. Maybe because of an infinite loop somewhere.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int present_flag;
  int binary_search(int array[],int low,int high,int key)
  {
  int mid=(high + low)/2;
  if(low&lt;=high)
  {
      if (array[mid] == key)
      {
      printf("Key found at index %d \n",mid);
      return 1;
      }
          else if (array[mid] &gt;key)
          return 0+binary_search(array,low,mid,key);
              else 
              return 0+binary_search(array,mid+1,high,key);;
  }
  else return 0;
  }
  main()
  {
  int array[9],i,n,key;
  printf("Enter 9 numbers in asc order \n");
  for(i=0;i&lt;9;i++)
  scanf("%d",&amp;n);
  printf("Enter number to be searched\n");
  scanf("%d",&amp;key);
  present_flag=binary_search(array,0,8,key);
  if (present_flag==0 )
  printf("Number not present in array\n");
  }
  </code></pre>