0% found this document useful (0 votes)
49 views3 pages

Week 6 Assignment 1.

The document contains instructions for 6 assignments involving 2D arrays in C++. The assignments involve: 1) Storing a value in every index of a 2D matrix. 2) Adding two matrices and saving the result. 3) Finding the sum of elements within a given rectangular region of a matrix. 4) Finding the largest element in a 2D array. 5) Finding the row with the maximum sum in a given matrix. 6) Displaying the middle row and middle column of a square matrix. The document emphasizes solving the assignments independently without direct copying to build a strong programming foundation.

Uploaded by

Swapnil singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views3 pages

Week 6 Assignment 1.

The document contains instructions for 6 assignments involving 2D arrays in C++. The assignments involve: 1) Storing a value in every index of a 2D matrix. 2) Adding two matrices and saving the result. 3) Finding the sum of elements within a given rectangular region of a matrix. 4) Finding the largest element in a 2D array. 5) Finding the row with the maximum sum in a given matrix. 6) Displaying the middle row and middle column of a square matrix. The document emphasizes solving the assignments independently without direct copying to build a strong programming foundation.

Uploaded by

Swapnil singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ Assignments | 2D Arrays - 1 | Week 6

Q1: Write a program to store 10 at every index of a 2D matrix with 5 rows and 5 columns.

Write a program to add two matrices and save the result in one of the given matrices.

Input 1:

123

456

789

458

008

120

Output 1:

5 7 11

4 5 14

8 10 9

Q3: Given a matrix ‘A’ of dimension n x m and 2 coordinates (l1, r1) and (l2, r2). Return the sum of the
rectangle from (l1,r1) to (l2, r2).

Input 1:

1 2 -3 4

0 0 -4 2

1 -1 2 3

-4 -5 -7 0

l1 = 1, r1 = 2 , l2 = 3 , r2 = 3

Output 1: -4

Input 2:

1 2 -3 4
0 0 -4 2

1 -1 2 3

-4 -5 -7 0

l1 = 1, r1 = 0 , l2 = 0 , r2 = 3

Output 1: 2

Q4: Write a C++ program to find the largest element of a given 2D array of integers.

Input 1:

1346

2457

3568

4679

Output 1: 9

Q5: Write a program to print the row number having the maximum sum in a given matrix.

Input 1:

1357

3478

1 4 12 3

Output 1: 2

Explanation : The 2nd row has the maximum sum i.e. 1+4+12+3 = 20

Q6: Write a function which accepts a 2D array of integers and its size as arguments and displays the
elements of middle row and the elements of middle column.

[Assuming the 2D Array to be a square matrix with odd dimensions i.e. 3x3, 5x5, 7x7 etc...]

Input 1:

12345

34567

76543

87654

1 2 37 8 0

Output 1:
3

7 6 5 4 3
6
37

Note:- Please try to invest time doing the assignments which are necessary to build a strong
foundation. Do not directly Copy Paste using Google or ChatGPT. Please use your brain .

You might also like