![]() |
VOOZH | about |
Here, we will see how to interchange the elements of first and last in a matrix across rows. Below are the examples:
Input: 6 3 1
4 5 2
2 4 9
Output: 2 4 9
4 5 2
6 3 1Input: 1 3 5
4 5 2
2 2 4
Output: 2 2 4
4 5 2
1 3 5
Approach: The approach is very simple, swap the elements of the first and last row of the matrix in order to get the desired matrix as output.
Below is the C program to interchange the elements of first and last in a matrix across rows:
Input Matrix: 6 3 1 4 5 2 2 4 9 Output Matrix: 2 4 9 4 5 2 6 3 1
Time Complexity: O(n2)
Auxiliary Space: O(1)