Find the product of sum of two diagonals of a square Matrix | C ++ program to find the product of the sum of diagonals . ; Function to find the product of the sum of diagonals . ; Initialize sums of diagonals ; Return the answer ; Driven code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long product ( vector < vector < int > > & mat , int n ) { long long d1 = 0 , d2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { d1 += mat [ i ] [ i ] ; d2 += mat [ i ] [ n - i - 1 ] ; } return 1LL * d1 * d2 ; } int main ( ) { vector < vector < int > > mat = { { 5 , 8 , 1 } , { 5 , 10 , 3 } , { -6 , 17 , -9 } } ; int n = mat . size ( ) ; cout << product ( mat , n ) ; return 0 ; }