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) | |||
|
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
}
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
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