Implemened problem 6