Code for problem 39E.