Solution in c to problem 18