Question: Diagonal Difference HackerRank Pseudocode and C++: Given a square matrix, calculate the absolute difference between the sums of its diagonals. Function Description Complete the diagonalDifference

Diagonal Difference HackerRank Pseudocode and C++: Given a square matrix, calculate the absolute difference between the sums of its diagonals.

Function Description

Complete the diagonalDifference function described below to calculate the absolute difference between diagonal sums.

diagonalDifference( integer: a_size_rows, integer: a_size_cols, integer array: arr)
Parameters:
a_size_rows: number of rows in array a_size_cols: number of columns in array a: array of integers to process
Returns: integer value that was calculated

Constraints

-100 < = elements of the matrix < = 100

Raw Input Format

The first line contains a single integer, denoting the number of rows and columns in the matrix . The next lines denote the matrix 's rows, with each line containing space-separated integers describing the columns.

Sample Input 0

3 11 2 4 4 5 6 10 8 -12 

Sample Output 0

15 

Explanation 0

The primary diagonal is:

11 5 -12 

Sum across the primary diagonal: 11 + 5 - 12 = 4

The secondary diagonal is:

 4 5 10 

Sum across the secondary diagonal: 4 + 5 + 10 = 19 Difference: |4 - 19| = 15

Note: |x| is the absolute value of x

#include

using namespace std;

/* * Complete the diagonalDifference function below. */ int diagonalDifference(vector> a) { /* * Write your code here. */

}

Please write the pseudocode along with the C++ source and explain in full detail both the pseudocode and the source code. Thanks. Mathematically speaking, I know we are trying to sum both diagonal lines of a square matrix and so we would have to use matrix notation for the pseudocode to accompisl the diagonal difference. Is this right?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!