
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to check whether the given matrix is a Toeplitz matrix using C#?
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
Example 1
[[1,2,3,4], [5,1,2,3], [9,5,1,2]]
Output −
true
In the above grid, the diagonals are −
"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
In each diagonal all elements are the same, so the answer is True.
Example 2
Input: matrix [[1,2], [2,2]]
Output −
false
The diagonal "[1, 2]" has different elements
Code
public class Matrix { public bool ToeplitzMatrix(int[,] mat) { int row = getMatrixRowSize(mat); int col = getMatrixColSize(mat); for (int i = 1; i < row; i++) { for (int j = 1; j < col; j++) { if (mat[i, j] != mat[i - 1, j - 1]) { return false; } } } return true; } private int getMatrixRowSize(int[,] mat) { return mat.GetLength(0); } private int getMatrixColSize(int[,] mat) { return mat.GetLength(1); } } static void Main(string[] args) { Matrix m = new Matrix(); int[,] mat = new int[3, 4] { { 1, 2, 3, 4 }, { 5, 1, 2, 3 }, { 9, 5, 1, 2 } }; Console.WriteLine(m.ToeplitzMatrix(mat)); }
Output
TRUE
- Related Articles
- Program to check whether given matrix is Toeplitz Matrix or not in Python
- Find if given matrix is Toeplitz or not in C++
- How to check in R whether a matrix element is present in another matrix or not?
- Swift program to check if a given square matrix is an Identity Matrix
- Which linear function of SciPy is used to solve Toeplitz matrix using Levinson Recursion?
- Check if a matrix is symmetric using Python
- C Program To Check whether Matrix is Skew Symmetric or not?
- C++ code to check given matrix is good or not
- Java Program To Determine If a Given Matrix is a Sparse Matrix
- Golang Program To Determine If a Given Matrix is a Sparse Matrix
- Check if the matrix is lower triangular using Python
- Check if a given matrix is sparse or not in C++
- Check if a given matrix is Hankel or not in C++
- Program to check if a matrix is Binary matrix or not in C++
- Check if a Matrix is Identity Matrix or not in Java?

Advertisements