Solution for ex 2