Code for problem 46C.