Code for problem 41E.