calculate the sum of diagonals in a matrix

前端 未结 5 1650
梦如初夏
梦如初夏 2020-12-16 01:45

I need to calculate the sum of two diagonals in a matrix in C++, I already have a solution for that but I must be dumb because I cant understand what it is doing, so I would

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 02:41

    int diag1=0;
    int diag2=0;
    
    for (i=0;i

    }

    To understand this algorithm better you should paint a matrix on you notebook and number it's elements with their position in matrix,then apply the algorithm step by step.I'm 100% sure that you will understand

提交回复
热议问题