completed problem 4 in C