generate functionWed, 08 Feb 2023

Write a program that prints the maximum element in the area below the main diagonal including the diagonal of the square matrix.

def max_under_diagonal(matrix): res = 0 for i in range(len(matrix) - 1): # no need to check the last row for j in range(i + 1): if matrix[i][j] > res: res = matrix[i][j] return res max_under_diagonal([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) # 15

Questions about programming?Chat with your personal AI assistant