xxxxxxxxxx
# Get the dimensions of the 2D array from the user
rows = int(input("Enter the number of rows: "))
cols = int(input("Enter the number of columns: "))
# Initialize an empty 2D array
matrix = []
# Get user input for each element in the array
for i in range(rows):
row = []
for j in range(cols):
element = int(input(f"Enter element at position ({i},{j}): "))
row.append(element)
matrix.append(row)
# Print the 2D array
for i in range(rows):
for j in range(cols):
print(matrix[i][j], end=" ")
print()