c++ - find sum of diagonal elements from given index in 2d array -
i have construct 2d array n,m rows , columns (n & m <= 5), user enters index(location) 2,3 (matrix[2][3]) it's assumed 2 numbers in bounds of matrix. on have find sum of left , right diagonal goes through number, number excluded sum. so example 2d array myarray[3][3] *1* 15 *2* 2 *71* 8 *5* 22 *5* so user enters 1,1 myarray[1][1], in case number 71, sum 1 + 5 + 2 + 5 ... , problem how can find diagonals without going out of bounds. for left top go: row-- column-- while(row >= 0|| column >= 0) left bottom: row++ colum++ while(row < n || column < m) right top: row-- column++ while(row >= 0 || column < m) right bottom: row++ column-- while(row < n || column >=0) (this bad written pseudo-code, sorry) it works fine when enter numbers aren't in top or bottom row, in cases located there program stops. what have pseudocode. first thought should using &&'s instead of ||'s when determining if location out of boun