Adding solution for problem 39 in c.