Adding solution for problem 18 in c.