Code for problem 4.4