Question
The left-to-right diagonal = . The right to left diagonal = . Their absolute difference is . Function description Complete the function in the editor
The left-to-right diagonal = . The right to left diagonal = . Their absolute difference is .
Function description
Complete the function in the editor below.
diagonalDifference takes the following parameter:
int arr[n][m]: an array of integers
Return
int: the absolute diagonal difference
Input Format
The first line contains a single integer, , the number of rows and columns in the square matrix .
Each of the next lines describes a row, , and consists of space-separated integers .
Constraints
-100≤ arr[i][j]≤ 100
Output Format
Return the absolute difference between the sums of the matrix's two diagonals as a single integer.
Sample Input:
Sum across the secondary diagonal: 4 + 5 + 10 = 19
Difference: |4 - 19| = 15
Note: |x| is the absolute value of x
Given a square matrix, calculate the absolute difference between the sums of its diagonals. For example, the square matrix is shown below: 123 456 989 The left-to-right diagonal. The right to left diagonal. Their absolute difference is
Step by Step Solution
3.44 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started