2-d array for printing both the digonal elements of a matrix...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shikha tripathi
    New Member
    • Jan 2014
    • 2

    2-d array for printing both the digonal elements of a matrix...

    what if we want to print both the diagonal elements!!!!
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Hi shikha tripathi and welcome to bytes.com!

    What you're looking for is probably the concept of nested loops; meaning, you can put one loop inside another. Here, an example:
    Code:
    int** matrix = ...;
    int m, n;
    for(m = 0; m < MATRIX_HEIGHT; m++) {
        for(n = 0; n < MATRIX_WIDTH; n++) {
            // access matrix[m][n] here
        }
    }
    Does that help?

    Comment

    Working...