Did Problem 9 in C#