Answer to Question #175339 in Python for VENKATA HARIKRISHNA

Question #175339

Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.


1
Expert's answer
2021-03-25T04:20:14-0400
M=int(input(""))
N=int(input(""))


numbers= []
#Get numbers from the user
for i in range(0,M):
    valuesStr=input("")
    values=valuesStr.split()
    for v in values:
        numbers.append(int(v))
    
#sort
numbers.sort()
numbers2D=[]
numbers2D = [numbers[r*N:(r+1)*N] for r in range(0,M)]
print()
#Display result
for row in numbers2D:
    for elem in row:
        print(elem, end=' ')
    print()

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

Bheem Reddy Malekadi
16.05.21, 16:26

Please explain this code

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS