Solution for ex5.