Code for problem 46D.