Week 8: Friday -------------- Q1. (30) A polynomial of degree n is stored in an array of size n+1. Note that the first element of the array stores the coefficient of the lowest degree and so on. For example, if a polynomial is 5 x^3 + 10 x^2 - 1, it is stored as {-1, 0, 10, 5}. Write a function to compute the products of two polynomials f(x) and g(x). Your function should have the following prototype: void multiply(double f[], double g[], double h[], int m, int n, int *k); f and g are the input polynomials of degree m and n respectively. And when the function returns, h should hold the product and *k should hold the degree of h. Note that k is a pointer to an integer, and the contents of k, i.e., *k can be changed inside the function. In the main function, declare two arrays of size 10 to store f(x) and g(x). Ask the user to enter m and n less than or equal to 9 and read the coefficients of f(x) into the first array and the coefficients of g(x) into the second array. Carefully declare a third array of sufficient size to store the product. Apply the multiply function on f(x) and g(x). Use the degree of h(x) returned through *k (see the above prototype) to print h. Q2. (70) Here is a description of an algorithm called the selection sort that, given an array of n numbers, sorts them in ascending order. 1. Select the minimum value in the array and swap it with the first element. 2. Select the next minimum value in the rest of the array (i.e., ignoring the first element) and swap it with the second element. 3. Do this for n-1 iterations. In the kth iteration, we will have the first (k-1) elements sorted. Find the next minimum value and swap it with the value at the kth location. For example, suppose n = 5 and the input array is: 5 2 1 3 4 First iteration, i.e., k = 1: smallest element from position to n-1 is 1; swap 1 and 5; Array becomes: 1 2 5 3 4 Second iteration, i.e., k = 2: smallest element from position 1 to n-1 is 2; swap 2 and 2; Array becomes: 1 2 5 3 4 Third iteration, i.e., k = 3: smallest element from position 2 to n-1 is 3; swap 3 and 5; Array becomes: 1 2 3 5 4 Fourth iteration, i.e., k = 4: smallest element from position 3 to n-1 is 4; swap 4 and 5; Array becomes: 1 2 3 4 5 Write a program that implements selection sort. The function should print the array contents before each iteration. In the main function, declare an array of size 8; ask the user to enter 8 integers into the array. Apply the sort function on this array.