There is a bug in this code; the inner most for loop should be: for(k=0;k<r2;k++) { ... }
Separate names with a comma.