Suppose I have an array A with n numbers, so that the first element of this array is even, and last one is odd- I would like to write an function which find index i , such that A is even and A[i+1] is odd. The function is to return the found index; if there is not any such index, return -1. I have been thinking of using binary search in that case. Here is what I have done so far: int findIndex(int A[], int n) { int left=0,right=n-1,mid,i; while(left<=right) { mid=(left+right)\2; if (A[mid]%2==0 && A[mid+1]%2!=0) return mid; else if (A[mid]%2!=0) right=mid-1; else left=mid+1; } return -1; } I am not sure... What do you think about it? Any help would be very appreciated. Login To add answer/comment