fork download
  1. import random
  2.  
  3. # Create a 4x4 list filled with random numbers
  4. rows = 4
  5. cols = 4
  6. matrix = [[random.randint(1, 100) for _ in range(cols)] for _ in range(rows)]
  7.  
  8. # Find the maximum element and its indices
  9. max_element = matrix[0][0]
  10. max_row = 0
  11. max_col = 0
  12.  
  13. for i in range(rows):
  14. for j in range(cols):
  15. if matrix[i][j] > max_element:
  16. max_element = matrix[i][j]
  17. max_row = i
  18. max_col = j
  19.  
  20. # Print the matrix and the indices of the maximum element
  21. print("Matrix:")
  22. for row in matrix:
  23. print(row)
  24.  
  25. print("\nMaximum element:", max_element)
  26. print("Indices of maximum element: Row =", max_row, ", Column =", max_col)
Success #stdin #stdout 0.03s 9880KB
stdin
Standard input is empty
stdout
Matrix:
[43, 56, 89, 1]
[58, 25, 70, 62]
[92, 5, 19, 74]
[96, 7, 48, 44]

Maximum element: 96
Indices of maximum element: Row = 3 , Column = 0