Friday, February 1, 2019

Matrix Subtraction

  • Problem Description

    Write a python program to create a NESTED LIST and subtract the two matrix. (Without Square Brackets)

    Hint:

    1. Input the number of rows and columns for First Matrix

    2. Input the number of rows and columns for Second Matrix

    3. Display the first matrix elements in Matrix format (Without commas and Square Bracket)

    4. Display the first matrix elements in Matrix format (Without commas and Square Bracket)

    5. Display the result of difference of two matrix (Without commas and Square Bracket)
  • CODING ARENA
  • a=int(input())
    b=int(input())
    x=[]
    y=[]
    for i in range(a):
        n=[]
        x.append(n)
        for j in range(a):
            z=int(input())
            n.append(z)
    for i in range(b):
        n=[]
        y.append(n)
        for j in range(b):
            z=int(input())
            n.append(z)
    print("Matrix 1")
    for i in range(a):
        for j in range(a):
            print(x[i][j],end=" ")
        print()
    print("Matrix 2")
    for i in range(b):
        for j in range(b):
            print(y[i][j],end=" ")
        print()
    print("Difference of Matrix")
    for i in range(a):
        for j in range(a):
            print(x[i][j]-y[i][j],end=" ")
        print()
  • Test Case 1

    Input (stdin)
    2
    
    2
    
    100
    
    150
    
    200
    
    250
    
    50
    
    100
    
    150
    
    200
    
    
    Expected Output
    Matrix 1
    
    100 150 
    
    200 250 
    
    Matrix 2
    
    50 100 
    
    150 200 
    
    Difference of Matrix
    
    50 50 
    
    50 50 
  • Test Case 2

    Input (stdin)
    3
    
    3
    
    190
    
    180
    
    170
    
    160
    
    150
    
    140
    
    130
    
    120
    
    110
    
    10
    
    20
    
    30
    
    40
    
    50
    
    60
    
    70
    
    80
    
    90
    
    
    Expected Output
    Matrix 1
    
    190 180 170 
    
    160 150 140 
    
    130 120 110 
    
    Matrix 2
    
    10 20 30 
    
    40 50 60 
    
    70 80 90 
    
    Difference of Matrix
    
    180 160 140 
    
    120 100 80 
    
    60 40 20

1 comment:

  1. EKWB EK-UNI Pump Bracket in UAE, Pump Bracket in UAE
    https://gccgamers.com/ekwb-ek-uni.html
    EKWB EK-UNI Pump Bracket in UAE, Safe Shopping Multiple Payment Options Express Delivery GCC Gamers Moneyback Guarantee.
    1633592624266-10

    ReplyDelete