Switched for loop to C style in getResidual.c