C program for Binary search algorithm

C program for binary search algorithm : Binary search is a searching algorithm which searches an element in the sorted list. In each step,binary search algorithm compares the input number(to be searched) with the value of the middle element of the array. If the values match, then a matching element has been found so its index, or position, is returned. Otherwise, if the searched number is less than the middle element’s value, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the input number is greater, on the sub-array to the right. If the remaining array to be searched is reduced to zero, then the number cannot be found in the array then a special “Not found” indication is returned. Let us see a basic implementation of binary search algorithm using iterations.

The above code is just an snippet to see how the binary search algorithm works. Now lets see the complete C program for binary search algorithm.

Note : The input list should be in sorted order (ascending order) else program will not work as expected. If you want to provide the unsorted list of elements as input then first of all you need to sort the elements and then do the binary search.

Well, I am software programmer and love to code. My hobbies is to do Hacking, Coding, Blogging, Web Designing and playing online games.
Feel free to contact me at shiviskingg@gmail.com or lokesh@hackingloops.com

6 COMMENTS

I simply want to tell you that I’m newbie to blogs and seriously enjoyed you’re web blog. Almost certainly I’m want to bookmark your blog . You amazingly come with very good posts. With thanks for sharing with us your web page.

I was suggested this web site by way of my cousin. I am now not certain whether or not this publish is written through him as nobody else understand such detailed about my difficulty. You are amazing! Thanks!

Thanks for every other informative website. Where else may just
I am getting that type of information written in such
a perfect means? I’ve a mission that I am just now working on, and
I’ve been at the look out for such info.