code for problem 2