Computer Science, asked by jananijohn8927, 9 months ago

Write a program to input any matrix and print both diagonal values of the matrix.

Answers

Answered by mohishkhan9996
0

Answer:

hey... mate

Program to print the Diagonals of a Matrix. The primary diagonal is formed by the elements A00, A11, A22, A33. Condition for Principal Diagonal: The row-column condition is row = column. The secondary diagonal is formed by the elements A03, A12, A21, A30. Condition for Secondary Diagonal: The row-column condition.

hope it usefull plzz mark as brainlist

Answered by ridhimakh1219
1

Write a program to input any matrix and print both diagonal values of the matrix

Explanation:

# Python Program to print both diagonal values of a Matrix

MAX = 50

# Print first Diagonal

def firstDiagonal(mat, n):

print("First Diagonal: ", end = "")

for i in range(n):

 for j in range(n):

  # Condition

  if (i == j):

   print(mat[i][j], end = ", ")

print()

# Function to print Second Diagonal

def secondDiagonal(mat, n):

print("Second Diagonal: ", end = "")

for i in range(n):

 for j in range(n):

  # Condition

  if ((i + j) == (n - 1)):

   print(mat[i][j], end = ", ")

print()

# Driver code

num = 4

arr = [[ 12,52,67,64 ],

 [ 86,67,78,67 ],

 [ 99,65,87,44 ],

 [ 15,76,89,95 ]]

firstDiagonal(arr, num)

secondDiagonal(arr, num)

Output

First Diagonal: 12, 67, 87, 95,

Second Diagonal: 64, 78, 65, 15,

Similar questions