C program for binary search

This C program performs binary search in an array. It prints the position of the element in the array if the searched element is present in the array, else prints that it is not present in the array.

In this program, it is assumed that the array is sorted in ascending order already. So the user is expected to enter integers in ascending order to perform binary search.

Program: Perform binary search in C

Output: Print position of the searched element using binary search

Enter number of elements: 6       
Enter 6 integers: 43 53 64 72 85 93
Enter value to find: 53
53 found at location 2.


Enter number of elements: 7
Enter 7 integers: 43 53 64 72 85 93 108
Enter value to find: 49
Not found! 49 is not present in the array.

Share your code and queries in the comments.

Share this code with your programmer friends.

Follow us on twitter.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

Your email address will not be published. Required fields are marked *