Code for problem 118.