Program 9.4 from chapter 9