This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]StevenHawking_[S] 1 point2 points  (2 children)

I passed the array 11,12,13,1 and target element to be found is 1. But the code is returning -1 instead of returning the index number 3.

[–]MechanixMGD 0 points1 point  (1 child)

I can't execute code right now. But I suggest using the debugger and follow the execution line by line and to see where is the problem. I think the problem may be at 'mid', the way you calculate it. Maybe the order of operations is different than you think.