Code for problem 337E.