main.c adapted to run code function.
need to test whether the algorithm is correct.