Code for problem 114.