Program 16.3 from chapter 16