Code for problem 24.