solved exercise 16 in chapter5