Question: write the code in c , dont chat gpt Perform a binary search on a 1 6 - element sorted array by passing half the

write the code in c, dont chat gpt
Perform a binary search on a 16-element sorted array by passing half the array
to a child process. The parent should define the array, print it and ask the user to
input a target value. The parent will compare the target value to the mid element, call
fork, and and the child will operate on half of the array. Similarly, the next child will
operate on 14 of the array and so on. The child process that finds the target value
should print its index in the terminal. If the target doesnt exist in the array, print -1.
Each parent should wait for their child to finish before returning. [25 pts]
Input: Define a 16-element array in the code. The array must be sorted.
Output: Output format should be as follows:
Array: 12345678910111213141516
Enter a target value: 6
Target values index: 5
Rubrics:
The student should have implemented the following things:
File q2.c containing the main function.
Defined a sorted 16-element array.
Asked user for target value.
A child should operate on half of the array of its parent at each fork level.
There will be, at most, 4 forking levels.
The correct index of the target value in the array is printed. If the target is not
in the array, -1 is printed.

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 Programming Questions!