0% found this document useful (0 votes)
31 views6 pages

2D Matrix Programming Challenges

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)
31 views6 pages

2D Matrix Programming Challenges

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

Multi-Dimensional Array related problems

(Total 15 questions)
SL Problem statement Difficulty
levels

1. WAP that will take n integers into a sqrt(n) by sqrt(n) array (2D) and show them as *
traditional matrix view.

Sample input Sample output


9 987
987654321 654
321
9 111
111222333 222
333

2. WAP that will take (m x n) integers into a m by n array (2D) and print them both row-wise *
and column-wise.

Sample input (m,n) Sample output


23 Row-wise: 1 2 3 6 5 4
123 Column-wise: 1 6 2 5 3 4
654
33 Row-wise: 1 1 1 2 2 2 3 3 3
111 Column-wise: 1 2 3 1 2 3 1 2 3
222
333

3. WAP that will take inputs of a 3 by 3 matrix into a 2D array. Now find the determinant of *
this matrix. [Link]

Sample input Sample output


123 0
456
789
4. WAP that will take inputs of a n sized square matrix into a 2D array. Now show all the *
elements of its two diagonals. Reference: [Link]

Sample input Sample output


5 Major diagonal: 1 4 2 9 4
12345 Minor diagonal: 5 2 2 7 1
54321
22222
67890
19374

5. WAP that will take the size of an identity matrix from the user and generate the identity *
matrix into a 2D array. Finally display it. Reference:[Link]

Sample input Sample output


5 10000
01000
00100
00010
00001

6. WAP that will take inputs of two m x n sized matrix into two 2D array, suppose A and B. *
Now do C = A + B. Finally display all the elements from matrix / 2D array C.

Sample input Sample output


23 234
123 456
234
111
222

7. WAP that will take inputs of two 3 x 3 sized matrix into two 2D array, suppose A and B. Now ***
do C = A * B (multiplication). Finally display all the elements from matrix / 2D array C.

Sample input Sample output


123 999
456 24 24 24
789 39 39 39
222
222
111
8. WAP that will take inputs of m x n sized matrix into a 2D array and find the maximum *
element with index locationfrom that matrix.

Sample input Sample output


33 Max: 9
123 Location: [2][1]
456
292
23 Max: 9
987 Location: [0][0]
345

9. WAP that will take (n x n) integer inputs into a square matrix of dimension n (where n must **
be an odd number). Then calculate sum of the integers at first row, last row and two
diagonals without overlap. Please see the sample input-output.

Sample input Sample output


5 52
12345
23416
34967
42678
54321

7 23
1111111
1111111
1111111
1111111
1111111
1111111
1111111
10. WAP that will take (n x n) integer inputs into a square matrix of dimension n (where n **
must be an odd number). Then calculate sum of the integers based on following position
pattern (consider only the boxed position during the sum). Please see the input-output.

Sample input Sample output


5 71
12345
23416
34967
42678
54321

7 25
1111111
1111111
1111111
1111111
1111111
1111111
1111111

11. WAP that will take (n x n) integer inputs into a square matrix of dimension n (where n **
must be an odd number). Then calculate sum of the integers based on following position
pattern (consider only the boxed position during the sum). Please see the input-output.

Sample input Sample output


5 65
12345
23416
34967
42678
54321

7 33
1111111
1111111
1111111
1111111
1111111
1111111
1111111
12. WAP that will take (m x n) integer inputs into a matrix of dimension m x n. Now reverse **
that matrix within itself and display it. Reversal means swap 1st column with the nth
column, swap 2nd column with the (n-1)th column and so on…

Sample input Sample output


33 321
123 654
456 292
292
26 654321
123456 456789
987654

13. WAP that will take (n x n) integer inputs into a square matrix of dimension n. Now **
determine whether the matrix is symmetric or not.
Reference: [Link]

Sample input Sample output


3 Yes
1 7 3
7 4 5
3 5 6
2 No
1 3
4 2

14. WAP that will take (m x n) positive integer inputs into a matrix of dimension m x n. Now ***
replace all the duplicate integers by -1 in that matrix. Finally display it.

Sample input Sample output


3 3 1 7 3
1 7 3 -1 4 5
7 4 5 -1 -1 6
3 5 6
26 2 -1 -1 -1 -1 -1
2 2 2 2 2 2 6 5 4 3 -1 1
6 5 4 3 2 1
15. WAP that will take (m x n) integer inputs into a matrix of dimension m x n. Now just *
simply add all the integers in that matrix and show the result.

Sample input Sample output


3 3 41
1 7 3
7 4 5
3 5 6
26 33
2 2 2 2 2 2
6 5 4 3 2 1

You might also like