Solution for problem 9. Fmt'ed