C++ Chapter 8 - 2D Array -Find the sum above or below the main diagonal in any n by n matrix, please solve the question with new solution, not the same as in questions bank

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 C++ Chapter 8 - 2D Array -Find the sum above or below the main diagonal in any n by n matrix, please solve the question with new solution, not the same as in questions bank

8:10
Write a code to find either the sum above or
below the main diagonal of an n by n matrix MAT
of integer values. The main diagonal represents
all the elements denoted by MAT[x][x] where x is
the values between 0 and n-1. First, the program
asks the user to enter the size of the matrix n.
Then the user should enter 0 to either find the
sum of the elements in the region above the
diagonal or 1 to find the sum of the elements
under the diagonal. Finally, the user has to insert
the n*n elements of the matrix in a row order
where the elements of the first row will be
inserted first and then the second row and so on.
The output simply represents the desired sum
value.
IMPORTANT NOTES:
• If the matrix size < 0, the output will be
"Negative input".
• If the matrix size = 0, the output will be "Zero
size matrix".
• If the user input for the desired region is not 0
or 1 then the output will be "Wrong entry".
• The user will not be given the chance to enter
the matrix values if any of the previous
conditions occured.
I/O
Program Input:
• Array size (n)
• Desired region(0 or 1)
• n*n integer elements
Program Output:
• A single line that shows the desired
sum value
Sample Testcase 0:
Input:
(-2)
Output:
Negative input
Sample Testcase 1:
Input:
0
Output:
Zero size matrix
Transcribed Image Text:8:10 Write a code to find either the sum above or below the main diagonal of an n by n matrix MAT of integer values. The main diagonal represents all the elements denoted by MAT[x][x] where x is the values between 0 and n-1. First, the program asks the user to enter the size of the matrix n. Then the user should enter 0 to either find the sum of the elements in the region above the diagonal or 1 to find the sum of the elements under the diagonal. Finally, the user has to insert the n*n elements of the matrix in a row order where the elements of the first row will be inserted first and then the second row and so on. The output simply represents the desired sum value. IMPORTANT NOTES: • If the matrix size < 0, the output will be "Negative input". • If the matrix size = 0, the output will be "Zero size matrix". • If the user input for the desired region is not 0 or 1 then the output will be "Wrong entry". • The user will not be given the chance to enter the matrix values if any of the previous conditions occured. I/O Program Input: • Array size (n) • Desired region(0 or 1) • n*n integer elements Program Output: • A single line that shows the desired sum value Sample Testcase 0: Input: (-2) Output: Negative input Sample Testcase 1: Input: 0 Output: Zero size matrix
8:10
Sample Testcase 2:
Input
32
Output:
Wrong entry
Sample Testcase 3:
Input
30123456789
Output:
11
Sample Testcase 4:
Input
31123456789
Output:
19
1 #include <iostream>
2 #include <cmath>
3 using namespace std;
4
5
int main()
6
{
7
int s, region;
cin>>s>>region;
int MAT[s] [s];
//Start your code Here
return 0;
88
9
10
11
12
13
14
15
16
17
18
19
Information
Author(s)
Deadline
Status
Grade
}
Submit
Saadeh Sweidan
07/06/2022 23:59:59
Succeeded
100.0%
(((²)
Transcribed Image Text:8:10 Sample Testcase 2: Input 32 Output: Wrong entry Sample Testcase 3: Input 30123456789 Output: 11 Sample Testcase 4: Input 31123456789 Output: 19 1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 5 int main() 6 { 7 int s, region; cin>>s>>region; int MAT[s] [s]; //Start your code Here return 0; 88 9 10 11 12 13 14 15 16 17 18 19 Information Author(s) Deadline Status Grade } Submit Saadeh Sweidan 07/06/2022 23:59:59 Succeeded 100.0% (((²)
Expert Solution
steps

Step by step

Solved in 4 steps with 8 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education