Given a 4 x 4 matrix, we have to interchange the elements of first and last row and show the resulting matrix.
Input : 3 4 5 0 2 6 1 2 2 7 1 2 2 1 1 2 Output : 2 1 1 2 2 6 1 2 2 7 1 2 3 4 5 0 Input : 9 7 5 1 2 3 4 1 5 6 6 5 1 2 3 1 Output : 1 2 3 1 2 3 4 1 5 6 6 5 9 7 5 1
The approach is very simple, we can simply swap the elements of first and last row of the matrix inorder to get the desired matrix as output.
Below is the implementation of the approach :
9 9 7 7 4 7 6 5 3 2 1 8 8 9 7 6
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Interchange elements of first and last columns in matrix
- Program to Interchange Diagonals of Matrix
- Remove first X rows and columns from a matrix
- Common elements in all rows of a given matrix
- Maximum difference of sum of elements in two rows in a matrix
- Find distinct elements common to all rows of a matrix
- Maximize sum by selecting M elements from the start or end of rows of a Matrix
- Ways of filling matrix such that product of all rows and all columns are equal to unity
- Enlarge a Matrix such that each element occurs in R rows and C columns
- Remove any corner X rows and columns from a matrix
- Number of rows and columns in a Matrix that contain repeated values
- Maximum increase in value of Matrix to keep maximum rows and columns unchanged
- Minimize cost to convert a given matrix to another by flipping columns and reordering rows
- Print unique rows in a given boolean matrix
- Find a common element in all rows of a given row-wise sorted matrix
- Count all sorted rows in a matrix
- Find all permuted rows of a given row in a matrix
- Find pair of rows in a binary matrix that has maximum bit difference
- Check if all rows of a matrix are circular rotations of each other
- Find duplicate rows in a binary matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.