generate functionTue, 07 Mar 2023

The program takes two natural numbers as input. n and m are the number of rows and columns in the matrix, then n lines of m integers each, separated by a space character. Write a program that finds the indices (row and column) of the first occurrence of the maximum element. Input Data Format Two numbers n and m are given as input to the program on different lines — the number of rows and columns in the matrix, then the matrix elements themselves row by row separated by a space.

def max_elem(n, m, matrix): max_num = 0 index = [] for i in range(n): for j in range(m): if matrix[i][j] > max_num: max_num = matrix[i][j] index = [i, j] return index n = int(input()) m = int(input()) matrix = [[int(j) for j in input().split()] for i in range(n)] print(*max_elem(n, m, matrix))

Questions about programming?Chat with your personal AI assistant