C Program to search element from a sorted array using Binary Search

C Program to search element from a sorted array using Binary Search



Problem Definition

We have to implement a C program that will search a value from a Sorted Integer Array using Binary Search Algorithms. The Search value will be a user input value.


Solution/ Source Code

Here is the Souce C code to find whether a search element is present in the array or not using Binary Search Algorithms. The below code is tested multiple times successfully using gcc Compiler on DEV C++ Windows 10 Platform. Output results are also shown below.




Program Output


Enter the number of elements=5

a[0]= 10

a[1]= 20

a[2]= 30

a[3]= 40

a[4]= 50

Enter the value to be searched=40

value 40 is present in possition 4.

--------------------------------

Enter the number of elements=5

a[0]= 15

a[1]= 25

a[2]= 35

a[3]= 45

a[4]= 55

Enter the value to be searched=50

value 50 is not present in the array.

--------------------------------

Enter the number of elements=4

a[0]= -23

a[1]= -11

a[2]= 4

a[3]= 67

Enter the value to be searched=-11

value -11 is present in possition 2.

--------------------------------

Back to Top

Comments

Also Check Out

Write a C program to convert Infix to Postfix Expression

C Program to Print Pascal's Triangle