Solved problem 9 in C