Intanto dovrebbe essere

codice:
for(k=j-1; k<riemp1-1; k++)