Code for problem 42D.