Eliminar las primeras X filas y columnas de una array

Dado un entero X y una array cuadrada mat[][] , la tarea es eliminar las primeras X filas y columnas de la array dada e imprimir la array actualizada.
Ejemplos: 
 

Entrada: mat[][] = { 
{1, 2, 3, 4}, 
{5, 6, 7, 8}, 
{8, 9, 4, 2}, 
{4, 8, 9, 2} }, 
X = 2 
Salida: 
4 2 
9 2
Entrada: mat[][] = { 
{1, 2, 3}, 
{4, 5, 6}, 
{7, 8, 9} }, 
X = 1 
Salida: 
5 6 
8 9 
 

Enfoque: Imprime los elementos de la array arr[i][j] para todo i, j ∈ [X, N – 1] donde N es el orden de la array cuadrada dada.
A continuación se muestra la implementación del enfoque anterior: 
 

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

Python3

# Python3 implementation of the approach
 
# Function to print the matrix after
# ignoring first x rows and columns
def remove_row_col(arr, n, x):
 
    # Ignore first x rows and columns
    for i in range(x, n):
        for j in range(x, n):
            print(arr[i][j], end = " ")
         
        print()
 
# Driver Code
if __name__ == "__main__":
 
    # Order of the square matrix
    n = 3
    MAX = 50
    arr = [[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]]
 
    x = 1
    remove_row_col(arr, n, x)
     
# This code is contributed by Rituraj Jain

C#

// C# implementation of the approach
using System;
 
class GFG
{
    // 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++)
            {
                Console.Write(arr[i, j] + " ");
            }
            Console.WriteLine();
        }
    }
     
    // Driver Code
    public static void Main()
    {
        // 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 Ryuga

PHP

<?php
// PHP implementation of the approach
 
$MAX = 50;
 
// Function to print the matrix after
// ignoring first x rows and columns
function remove_row_col($arr, $n, $x)
{
 
    // Ignore first x rows and columns
    for ($i = $x; $i < $n; $i++)
    {
        for ($j = $x; $j < $n; $j++)
        {
            echo $arr[$i][$j] . " ";
        }
        echo "\n";
    }
}
 
// Driver Code
 
// Order of the square matrix
$n = 3;
$arr = array(array( 1, 2, 3 ),
             array( 4, 5, 6 ),
             array( 7, 8, 9 ));
 
$x = 1;
remove_row_col($arr, $n, $x);
 
// This code is contributed by ihritik
?>

Javascript

<script>
 
// Javascript implementation of the approach
 
 
let MAX = 50;
 
// Function to print the matrix after
// ignoring first x rows and columns
function remove_row_col(arr,n,x)
{
 
    // Ignore first x rows and columns
    for (let i = x; i < n; i++)
    {
        for (let j = x; j < n; j++)
        {
            document.write( arr[i][j] + " ");
        }
        document.write("<br>");
    }
}
 
// Driver Code
 
    // Order of the square matrix
    let n = 3;
    let arr = [[ 1, 2, 3 ],
               [ 4, 5, 6 ],
               [ 7, 8, 9 ]];
 
    let x = 1;
    remove_row_col(arr, n, x);
 
 
// This code is contributed by sravan kumar
 
    </script>
Producción: 

5 6 
8 9

 

Publicación traducida automáticamente

Artículo escrito por VISHAL_PERIYASAMY_R y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *