Programming Excercise 2 solution