Find difference between sums of two diagonals | C ++ program to find the difference between the sum of diagonal . ; Initialize sums of diagonals ; Absolute difference of the sums across the diagonals ; Driven Program
#include <bits/stdc++.h> NEW_LINE #define MAX  100 NEW_LINE using namespace std ; int difference ( int arr [ ] [ MAX ] , int n ) { int d1 = 0 , d2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { d1 += arr [ i ] [ i ] ; d2 += arr [ i ] [ n - i - 1 ] ; } return abs ( d1 - d2 ) ; } int main ( ) { int n = 3 ; int arr [ ] [ MAX ] = { { 11 , 2 , 4 } , { 4 , 5 , 6 } , { 10 , 8 , -12 } } ; cout << difference ( arr , n ) ; return 0 ; }