<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 找出兩個對角線之和之間的差 > 原文: [https://www.geeksforgeeks.org/find-difference-between-sums-of-two-diagonals/](https://www.geeksforgeeks.org/find-difference-between-sums-of-two-diagonals/) 給定 **n X n** 的矩陣。 任務是計算對角線總和之間的絕對差。 **示例**: ``` Input : mat[][] = 11 2 4 4 5 6 10 8 -12 Output : 15 Sum of primary diagonal = 11 + 5 + (-12) = 4. Sum of primary diagonal = 4 + 5 + 10 = 19. Difference = |19 - 4| = 15. Input : mat[][] = 10 2 4 5 Output : 7 ``` 計算平方矩陣的兩個對角線的和。 沿著矩陣的第一個對角線,行索引=列索引,即如果 i = j,則 mat [i] [j]位于第一個對角線上。 沿著另一個對角線,行索引= n – 1 –列索引,即如果 i = n-1-j,則 mat [i] [j]位于第二對角線上。 通過使用兩個循環,我們遍歷整個矩陣并計算矩陣對角線上的總和。 以下是此方法的實現: ## C++ ```cpp // C++ program to find the difference // between the sum of diagonal. #include <bits/stdc++.h> #define MAX 100 using namespace std; int difference(int arr[][MAX], int n) { ????// Initialize sums of diagonals ????int d1 = 0, d2 = 0; ????for (int i = 0; i < n; i++) ????{ ????????for (int j = 0; j < n; j++) ????????{ ????????????// finding sum of primary diagonal ????????????if (i == j) ????????????????d1 += arr[i][j]; ????????????// finding sum of secondary diagonal ????????????if (i == n - j - 1) ????????????????d2 += arr[i][j]; ????????} ????} ????// Absolute difference of the sums ????// across the diagonals ????return abs(d1 - d2); } // Driven Program int main() { ????int n = 3; ????int arr[][MAX] = ????{ ????????{11, 2, 4}, ????????{4 , 5, 6}, ????????{10, 8, -12} ????}; ????cout << difference(arr, n); ????return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看