Answer to Question #242844 in Python for Rishi

Question #242844
Given a M x N matrix write a program to print the matrix after ordering all the elements of the matrix in increase order
1
Expert's answer
2021-09-30T00:57:37-0400
M=int(input("Enter the number of rows: "))
N=int(input("Enter the number of columns: "))
num= []
for i in range(0,M):
    valStr=input("")
    val=valStr.split()
    for v in val:
        num.append(int(v))
num.sort()
num2D=[]
num2D = [num[x*N:(x+1)*N] for x in range(0,M)]
print()
for row in num2D:
    for element in row:
        print(element, 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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS