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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Interchange elements of first and last columns in 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
- Program to Interchange Diagonals of Matrix
- Find all permuted rows of a given row in a matrix
- Count all sorted rows in a matrix
- Remove first X rows and columns from a matrix
- Print unique rows in a given boolean matrix
- Count rows in a matrix that consist of same element
- Remove any corner X rows and columns from a matrix
- Check if all rows of a matrix are circular rotations of each other
- Find duplicate rows in a binary matrix
- Enlarge a Matrix such that each element occurs in R rows and C columns
- Number of rows and columns in a Matrix that contain repeated values
- Python Counter| Find duplicate rows in a binary matrix
- Python | Print unique rows in a given boolean matrix using Set with tuples
- Find a common element in all rows of a given row-wise sorted matrix
- Find pair of rows in a binary matrix that has maximum bit difference
- Ways of filling matrix such that product of all rows and all columns are equal to unity
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.