generate functionFri, 10 Feb 2023

The input is a natural number n — the number of rows and columns in the square matrix. Next, the elements of the matrix are entered line by line with a space. Output the maximum element located on the main diagonal and below it

def matrix_sum(n): matrix = [] for i in range(n): matrix_elements = list(map(int, input().split(' '))) matrix.append(matrix_elements) max_sum = matrix[0][0] i = 0 while i < n: if sum(matrix[i][:i]) > max_sum: max_sum = sum(matrix[i][:i]) i += 1 return max_sum

Questions about programming?Chat with your personal AI assistant