Program 9.3 from chapter 9