Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago