solving question 7(modification)