Code for problem 5.