Adding solution for problem 42 in c.