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 the main diagonal

# 1 2 3 # 4 5 6 # 7 8 9 def add(a, b): return a + b def max_el(a): if n == 1: return a[0][0] if n == 2: return max(a[0][0], a[1][0], a[1][1]) res = a[0][0] for i in range(len(a)): for j in range(len(a[i])): if i == j: if a[i][j] > res: res = a[i][j] if i > j: if a[i][j] > res: res = a[i][j] return res n = int(input()) a = [] for i in range(n): a.append(list(map(int, input().split()))) print(max_el(a))

Questions about programming?Chat with your personal AI assistant