Below function has problem: int bsearch_recursive(int a[], int low, int high, int x) When you call this function recursively, you should return the value as shown below int mid = (low + high)/2; if(x a[mid]) return bsearch_recursive(a, mid+1, high, x); // added return else return a[mid]; If you don't return from some code paths of a function that returns, the code behavious is. As side notes • if you intend to use this code for very large arrays, (low + high) may overflow, so use int mid = low + (high - low)/2; • To make sure your compiler warns you about this compile with -Wall option. • Returning -1 in case of error is not a good idea if array may contain both positive and negative numbers. Backtrack 5 R3 Iso Highly Compressed here.
C Program to perform binary search on array using recursion [crayon-581eb7aa38cf/] Output: [crayon-581eb7aa38d2b414081291/]. C program for binary search: This code implements binary search in C language. It can only be used for sorted arrays, but it's fast as compared to linear search. C Program to perform binary search on array using recursion [crayon-581eb7aa38cf/] Output: [crayon-581eb7aa38d2b414081291/]. C program for binary search using recursion. Write a simple code for binary search using function recursion in c programming language. Int a[10],i,n,m,c,l,u; printf('Enter the size of an array: '); scanf('%d',&n); printf('Enter the elements of the array: ' ).