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.
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.
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
Related questions
Question
C++
Chapter 8 - 2D Array -Find the sum above or below the main diagonal in any n by n 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
8
int s, region;
cin>>s>>region;
int MAT[s] [s];
//Start your code Here
return 0;
9
10.
11
12
13
14
15
16
17
18 }
19
Information
Author(s)
Deadline
Status
20
Submit
Saadeh Sweidan
07/06/2022 23:59:59
Succeeded](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F79eef94c-4bfb-4682-9caf-4f06e50ac1f0%2Fd568cfd7-29c4-45bc-92e3-48899191331b%2Fgufikp7_processed.jpeg&w=3840&q=75)
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
8
int s, region;
cin>>s>>region;
int MAT[s] [s];
//Start your code Here
return 0;
9
10.
11
12
13
14
15
16
17
18 }
19
Information
Author(s)
Deadline
Status
20
Submit
Saadeh Sweidan
07/06/2022 23:59:59
Succeeded
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F79eef94c-4bfb-4682-9caf-4f06e50ac1f0%2Fd568cfd7-29c4-45bc-92e3-48899191331b%2Fwhvaqi_processed.jpeg&w=3840&q=75)
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
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education