Solve problem_3 in c