C procedure for problem 2
Improve C algorithm