Completed problem 7 in C