Question: Assignment Description Your task is to write a C program that implements the binary search algorithm. The program should search for a given element in

Assignment Description
Your task is to write a C program that implements the binary search algorithm. The program should
search for a given element in a sorted array of integers and output the index of the element if it is found.
If the element is not in the array, the program should print "Element not found."
Requirements
Your program must read a sorted array of integers and the element to be searched from the user.
Implement the binary search algorithm to find the index of the given element.
The output should either be the index of the element (if found) or the message "Element not
found."
Test Cases
You should test your program with the following cases and ensure it produces the correct output:
Input: Sorted Array: {2,4,6,8,10,12,14,16}, Element to be searched: 8
Output: Index of 8 is 3
Input: Sorted Array: {-5,0,3,7,9,11,15}, Element to be searched: 7
Output: Index of 7 is 3
Input: Sorted Array: {1,3,5,7,9}, Element to be searched: 4
Output: Element not found.
 Assignment Description Your task is to write a C program that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!