Week 6: Thursday ---------------- Q1. (30) Write a function to recursively compute the harmonic mean of an array of numbers. In the main function, create an array of size 10. Input integers from the user till a negative integer is input or the 10 elements have been filled up. Save the number of valid entries of the array in a variable. Find the harmonic mean of the elemnts of this array. Q2. (70) In the main function, input a sorted array of 10 integers. You can assume that the user will input distinct integers in an increasing order. Now input another integer q from the user. Write a recursive function search that checks whether q is present in the array. If q is present, it returns the index where q occurs in the array; otherwise, it returns -1. Note that you must implement the function search as a recursive function: int search(int[] a, int q, int start, int end) where start and end denote the starting and ending indexes of the array where the search will be conducted. Since the array is sorted, a new way of searching will be used. First, the element to be searched q is compared with the middle element of the array. The middle elemnt is at the index mid = (start + end) / 2. Now there are three possibilities: (a) a[mid] is q. Return mid. (b) a[mid] < q. Since the array is sorted, q cannot lie on the left side of the array. So the part of the array now needs to be searched is from mid + 1 to end. (c) a[mid] > q. Since the array is sorted, q cannot lie on the right side of the array. So the part of the array now needs to be searched is from start to mid - 1. Take care of the base cases, i.e., when the array contains one element or no elements. Example: Input is 2 4 6 8 9 10 12 13 14 15 (i) Search for q = 13 Compare with middle element 9. Then search right side, i.e., from 10 to 15. Again, compare with middle element, i.e., 13. Return the index 7. (ii) Search for q = 6 Compare with middle element 9. Then search left side, i.e., from 2 to 8. Again, compare with middle element, i.e., 4. Then search right side, i.e., from 6 to 8. Now, compare with middle element, i.e., 6. Return the index 2. (iii) Search for q = 5 Compare with middle element 9. Then search left side, i.e., from 2 to 8. Again, compare with middle element, i.e., 4. Then search right side, i.e., from 6 to 8. Now, compare with middle element, i.e., 6. Next, search the left side. Since the left side is empty, return -1.