Friday, February 1, 2019

Print Diagonal Elements

  • Problem Description

    Write a python program to create a NESTED LIST and print the diagonal elements of the matrix

    Hint:

    1. Input the number of rows First Matrix

    2. Input the number of Columns for Second Matrix

    3. Display the diagonal elements in the matrix
  • CODING ARENA
  • a=int(input())
    b=int(input())
    for i in range(a):
        for j in range(b):
            x=int(input())
            if(i==j):
                print(x)
  • Test Case 1

    Input (stdin)
    3
    
    3
    
    10
    
    20
    
    30
    
    40
    
    50
    
    60
    
    70
    
    80
    
    90
    
    
    Expected Output
    10
    
    50
    
    90
  • Test Case 2

    Input (stdin)
    2
    
    2
    
    10
    
    20
    
    30
    
    40
    
    
    Expected Output
    10
    
    40

No comments:

Post a Comment