how to pick out the diagonal elements of 5*5 matrix

compare the matrix with its index value matrix and figure out the index values of respective diagonal elements needed

  • in the first diagonal i and j values are same (i==j)
  • in the second diagonal if you closely observe , you can find … j=matrix.length - i - 1

generally we loop through this matrix rows and columns using for loop , now if you add these conditions , the requisite elements can be extracted.

Pseudocode:

Matrix=[4x4];

for loop(i ……..){

for loop(j……..){

  • /include the conditions\*

if(condition 1 for diagonal 1)

push the matrix[i][j] in to an array

if(condition 2 for diagonal 2)

push the matrix[i][j] in to an another array

}

}

the end

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response