Code for problem 39B.
Code for problem 39D.