solved exercise 9 in chapter5