
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Print matrix in diagonal pattern
Given a 2d array of n*n and the task is to find the antispiral arrangement of the given matrix
Input : arr[4][4]={1,2,3,4, 5,6,7,8, 9,10,11,12 13,14,15,16} Output : 1 6 11 16 4 7 10 13
Algorithm
START Step 1 -> declare start variables as r=4, c=4, i and j Step 2 -> initialize array as mat[r][c] with elements Step 3 -> Loop For i=0 and i<r and i++ Print mat[i][j] Step 4 -> print
Step 5 -> Loop For i=0 and i<r and i++ Print mat[i][4-1-i] End STOP
Example
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { int R=4,C=4,i,j; int mat[R][C] = { {1,2,3, 4}, {5,6,7,8},{9,10,11,12},{13,14,15,16}}; for(i=0;i<R;i++) { cout<<mat[i][i]<<" "; } cout<<"
"; for(i=0;i<R;i++) { cout<<mat[i][4-1-i]<<" "; } }
Output
if we run the above program then it will generate the following output
1 6 11 16 4 7 10 13
- Related Articles
- Swift Program to Print Diagonal Matrix Pattern
- Program to print a matrix in Diagonal Pattern.
- Print numbers in matrix diagonal pattern in C Program.
- Golang program to print right diagonal matrix
- Print matrix in snake pattern in C Programming.
- Golang program to print the left diagonal matrix
- Swift Program to print the right diagonal matrix
- Swift Program to print the left diagonal matrix
- Python program to print matrix in a snake pattern
- Print concentric rectangular pattern in a 2d matrix in C++
- Print lower triangular matrix pattern from given array in C Program.
- Print matrix in snake pattern from the last column in C Programming.
- Program to check diagonal matrix and scalar matrix in C++
- Program to convert given Matrix to a Diagonal Matrix in C++
- Convert a single column matrix into a diagonal matrix in R.

Advertisements