Code for problem 87.