Answer to Question #217909 in Python for SIm

Question #217909
Given a 2D (2 dimensional) array, find the largest element in it. 
 
Write a function solution that accepts a 2D-array A and two integers M (number of rows) and N (number of columns). The function should return the largest element in an array. 
 
Input 
    2 
    3 
    1 4 5 
    2 3 0 
 
    
Output 
    5





1
Expert's answer
2021-07-16T10:25:49-0400
M = int(input())
N = int(input())

A = []
for i in range(M):
    row = [int(j) for j in input().split()]
    if len(row) != N:
        raise ValueError('Length of row is not N')
    A.append(row) 

largest = A[0][0]
for i in range(M):
    for j in range(N):
        if A[i][j] > largest:
            largest = A[i][j]

print(largest)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS