- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Print Matrix in Z form
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement −Given a square matrix of order n*n, we need to display elements of the matrix in Z form.
Z form is traversing the matrix in the following steps −
- Traverse the first row
- Now, traverse the second principal diagonal
- Finally, traverse the last row.
We will take an input matrix here implicitly taken to demonstrate the flow of code.demostrate
Example
arr = [[1, 2, 6, 9], [1, 2, 3, 1], [7, 1, 3, 5], [1, 8, 7, 5]] n = len(arr[0]) i = 0 for j in range(0, n-1): print(arr[i][j], end = ' ') k = 1 for i in range(0, n): for j in range(n, 0, -1): if(j == n-k): print(arr[i][j], end = ' ') break; k+= 1 # Print last row i = n-1; for j in range(0, n): print(arr[i][j], end = ' ')
Output
1 2 6 9 3 1 1 8 7 5
All variables and functions are declared in global scope as shown in the figure below.
Conclusion
In this article, we learned about the approach to Print Matrix in Z form.
- Related Articles
- C++ Program to Print Matrix in Z form?
- Java Program to Print Matrix in Z form
- Swift Program to Print Matrix numbers containing in Z form
- Program to Print the Squared Matrix in Z form in C
- Java program to print a given matrix in Spiral Form.
- Print matrix in antispiral form
- Python Program to Print an Identity Matrix
- Python program to print matrix in a snake pattern
- Program to print matrix elements in spiral order in python
- Print a matrix in Reverse Wave Form in C++
- Print a given matrix in zigzag form in C++
- Program to print a matrix in Diagonal Pattern.
- Golang Program to Print an Identity Matrix
- Swift program to Print an Identity Matrix
- Swift Program to Print Diagonal Matrix Pattern

Advertisements