Given an integer X and a square matrix mat[][], the task is to remove the first X rows and columns from the given matrix and print the updated matrix.
Examples:
Input: mat[][] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{8, 9, 4, 2},
{4, 8, 9, 2} },
X = 2
Output:
4 2
9 2Input: mat[][] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9} },
X = 1
Output:
5 6
8 9
Approach: Print the elements of the matrix arr[i][j] for all i, j ∈ [X, N – 1] where N is the order of the given square matrix.
Below is the implementation of the above approach:
C++
// C++ implementation of the approach #include <iostream> using namespace std; const int MAX = 50; // Function to print the matrix after // ignoring first x rows and columns void remove_row_col(int arr[][MAX], int n, int x) { // Ignore first x rows and columns for (int i = x; i < n; i++) { for (int j = x; j < n; j++) { cout << arr[i][j] << " "; } cout << endl; } } // Driver Code int main() { // Order of the square matrix int n = 3; int arr[][MAX] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; int x = 1; remove_row_col(arr, n, x); } |
Java
// Java implementation of the approach import java.io.*; class GFG { static int MAX = 50; // Function to print the matrix after // ignoring first x rows and columns static void remove_row_col(int arr[][], int n, int x) { // Ignore first x rows and columns for (int i = x; i < n; i++) { for (int j = x; j < n; j++) { System.out.print( arr[i][j] + " "); } System.out.println(); } } // Driver Code public static void main (String[] args) { // Order of the square matrix int n = 3; int arr[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; int x = 1; remove_row_col(arr, n, x); } } // This code is contributed by // shk |
5 6 8 9
Recommended Posts:
- Remove any corner X rows and columns from a matrix
- Ways of filling matrix such that product of all rows and all columns are equal to unity
- Sorting rows of matrix in descending order followed by columns in ascending order
- Sorting rows of matrix in ascending order followed by columns in descending order
- Count rows/columns with sum equals to diagonal sum
- Sum of columns of a 2-D Matrix where first element is odd
- Interchange elements of first and last columns in matrix
- Count all the columns in a matrix which are sorted in descending
- Common elements in all rows of a given matrix
- Find all permuted rows of a given row in a matrix
- Count all sorted rows in a matrix
- Interchange elements of first and last rows in matrix
- Count rows in a matrix that consist of same element
- Check if all rows of a matrix are circular rotations of each other
- Maximum difference of sum of elements in two rows in a 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 contribute@geeksforgeeks.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.



