Add #39 solutions in C and Ruby