Code for problem 387E.