# Thread: let hand diagonal traversal of a matrix

1. ## let hand diagonal traversal of a matrix

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









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++ ;
}
}
}
}``` 2. I can't understand your example or your code. 3. no one can ever understand my code. the idea is that if i am at element  i should not be bumble to do anything. once there is enough space to access m elements diagonal then it should move from  down one row and one element behind so  and if m where three it would then move on to  to it would traverse the matrix diagonal( as in    ) only backwards 4. sorry i have Figured out the issue, and its working the way it should now. could any one tell me how i delete this post, as i cant seem to find a way, and as it stands, its nether use nor ornament, being as no one can ever read my code. Popular pages Recent additions 