
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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 new solution, don't copy other solutions in questions bank
![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](https://content.bartleby.com/qna-images/question/49fcf38e-9dcc-4bc9-ac41-08938ff04e92/6eb790af-84ed-4326-b01b-01cd62a6def5/utnw05a_thumbnail.jpeg)
Transcribed Image Text: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
![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](https://content.bartleby.com/qna-images/question/49fcf38e-9dcc-4bc9-ac41-08938ff04e92/6eb790af-84ed-4326-b01b-01cd62a6def5/r7qkhlq_thumbnail.jpeg)
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 stepSolved in 4 steps with 4 images

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.Similar questions
- Javaarrow_forwardARRAY RANDOMIZER Create a program that shuffels all the elements present in an array. To shuffle an array, you need to do at least 500 random swaps of any elements in the array given below. Print the shuffled array in the output. {12, 54, 22, 100, -3, 5, 10, -33, 78, 90, 29, -45, 77, -9, 19, 21} Language: CPParrow_forwardLab. Exam Q3) Create an M-by-N array of any numbers. Move through the array, element by element, and set any value that is less than 0.2 to 0 and any value that is greater than (or equal to) 0.2 to 1.arrow_forward
- Please written by computer source (java)arrow_forwardProblem Description - JAVA PROGRAMMING Use a Two-dimensional (3x3) array to solve the following problem: Write an application that inputs nine numbers, each of which is between 1 and 10, inclusive. Display the array after the user inputs each value. Rotate/flip the array by changing places. Make the rows columns and vice versa. You have to move the elements to their new locations. Remember to validate the input and display an error message if the user inputs invalid data. Documentation and the screenshot(s) of the results. Example: 1 2 3 4 5 6 7 8 9 the result will be : 1 4 7 2 5 8 3 6 9arrow_forwardWarning ⚠️ Don't post AI generated answer or plagiarised answer. If I see these things I'll give you multiple downvotes and will report immediately.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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