Fully working c code.
Tighetened loops.
Further tightening of loops and verified accuracy of calculation.