Code for problem 407B.