我正在学习考试,我正在尝试处理动态矩阵.我遇到了一个关于计算矩阵的每个对角线之和的问题,该矩阵的值和大小由用户选择.我的程序的目的是打印,这要归功于一个函数,其参数是矩阵及其大小,即每个对角线和的值.我将向您展示代码并对其进行深入描述.
----------------
| 52 | 35 | 5 | Example of matrix.
---------------- Imagine the first diagonal to be the one which goes right-to-left
| 2 | 71 | 1 | and only consists in the number "47".
---------------- The second diagonal would be the one which goes right-to-left and
| 3 | 60 | 25 | consists in the number "15" and "79".
---------------- So to get the sum of the second diagonal it would be:
| 79 | …Run Code Online (Sandbox Code Playgroud)