Code for problem 49D.