solve problem 4 in c