Add C version of problem 2