Hi, I'm trying to get an array of n*n to sum up m values in the matrix going left diagonally
so for n = 3 and m = 2 i should only hit elements
[0][2]
[1][1]
[1][1]
[2][0]
[1][2]
[2][1]
however the way i have coded it seems to be going in to negative, non existent elements. i have fixed the code to travers the matrix horizontal, vertically and right diagonally, but cant seem to figure out where I'm
Code:
printf("\n\n ***** Diagonal left traversal ***** \n\n") ;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if((j-m) < (n+1) && (i+m) < (n+1)){
y = 0 ;
printf("\n\n ***** Diagonal left traversal ***** \n\n") ;
for (x = j; x < (j + m) ; x++) {
tempSum = tempSum + pMatrix[i+y][j-y];
printf("\n array location pMatrix[%d][%d] \n", i+y , j-y);
y++ ;
}
}
}
}