Code for problem 7.