Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions