Adding solution from problem 27 in c.