CSC601 Exam. Section C ====================== Sample question. Iteration with min search ------------------------------------------ Problem specification --------------------- Let x(1) = 0.3 x(2) = -0.3 x(i) = i + sin(x(i-2)), i = 3, 4, ... (1) Write a suitable C++ program that generates a sequence x(1), x(2), ..., x(n), for some n >= 3 which is entered by the user from keyboard. [8 marks] (2) Write a suitable addition to the code produced for (1) that finds in this sequence the value which is nearest to some whole number. E.g., for a sequence consisting of three numbers 3.34, -5.95, 10.06, the result will be -5.95. The difference between this value and its nearest whole number (it is 0.05) is smallest amongst all three values. [12 marks] Remarks. ------- To calculate the smallest whole number that is not less than x, you may call the ceil function with interface: double ceil(double x) e.g. ceil(52.31) will return 53.0 To calculate the largest whole number that is not greater than x, you may call the ceil function with interface: double floor(double x) e.g. floor(48.91) will return 48.0 To calculate the absolute value you may call the fabs function with interface: double fabs(double x) e.g.: fabs(3.21) will return 3.21; fabs(-3.14) will return 3.14. To calculate sin(x) you may call the sin with interface: double sin(double x) Both functions require inclusion of the math.h file in your program.