Solved problem 24 in C