solved exercise 2 in chapter5