Completed problem 22 in C