advertisement

M.Sc. in High-Performance Computing 5613 - C programming Assignment 1 Mike Peardon (mjp@maths.tcd.ie) School of Mathematics, TCD Rules To submit, make a single tar-ball with all your code and a pdf of any written part you want to include. Submit this via msc.tchpc.tcd.ie by Wednesday October 14th. Marks will be given for the efficiency of your implementation. Late submissions without prior arrangement or a valid explanation will result in reduced marks. Question 1. write a C function int fib(int k) which writes the k th entry in the Fibonacci sequence to the terminal using printf. fib should compute the sequence by recursive calls to itself. The Fibonacci sequence fk is defined by the recursion fk+1 = fk + fk−1 for k = 1, 2, 3, . . . and with f0 = f1 = 1. Test the function with a few values and then evaluate f42 . Why does your program take as long as it does? What is the order of the algorithm (in k)? Write a second version of the function int fib2(int k) which has the same functionality as fib but which uses an O(k) method to evaluate fk instead of recursion.