Given a 4 x 4 matrix, the task is to interchange the elements of first and last columns and show the resulting matrix.
Input: 8 9 7 6 4 7 6 5 3 2 1 8 9 9 7 7 Output: 6 9 7 8 5 7 6 4 8 2 1 3 7 9 7 9 Input: 9 7 5 1 2 3 4 1 5 6 6 5 1 2 3 1 Output: 1 7 5 9 1 3 4 2 5 6 6 5 1 2 3 1
The approach is very simple, we can simply swap the elements of first and last column of the matrix in order to get the desired matrix as output.
Below is the implementation of the above approach :
6 9 7 8 5 7 6 4 8 2 1 3 7 9 7 9
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 rows in matrix
- Program to Interchange Diagonals of Matrix
- Remove first X rows and columns from a matrix
- Sum of columns of a 2-D Matrix where first element is odd
- Maximize count of rows consisting of equal elements by flipping columns of a Matrix
- Ways of filling matrix such that product of all rows and all columns are equal to unity
- 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
- Enlarge a Matrix such that each element occurs in R rows and C columns
- Remove any corner X rows and columns from a matrix
- Sorting rows of matrix in ascending order followed by columns in descending order
- Print index of columns sorted by count of zeroes in the Given Matrix
- Sorting rows of matrix in descending order followed by columns in ascending order
- Count all the columns in a matrix which are sorted in descending
- Maximize sum of diagonal of a matrix by rotating all rows or all columns
- Check if the first and last digit of number N is prime and their sum is less than K
- Absolute difference between the first X and last X Digits of N
- Print the first and last character of each word in a String
- Program to check if first and the last characters of string are equal
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.