Code for problem 9.