
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Check if a given matrix is Hankel or not in C++
Suppose we have a square matrix, our task is to check whether the matrix is Hankel matrix or not. The Hankel matrix is a square matrix, in which each ascending skew-diagonal elements from left to right is constant. Suppose a matrix is like below −
1 | 2 | 3 | 4 | 5 |
2 | 3 | 4 | 5 | 6 |
3 | 4 | 5 | 6 | 7 |
4 | 5 | 6 | 7 | 8 |
5 | 6 | 7 | 8 | 9 |
To check whether the matrix is Hankel Matrix or not, we have to check whether mat[i, j] = ai+j or not. ai+j can be defined as −
$$a_{i+j}=\begin{cases}mat[i+j,0]< n\mat[i+j-n+1,n-1]otherwise\end{cases}$$
Example
#include <iostream> #define N 5 using namespace std; bool isHankelMat(int mat[N][N], int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i + j < n) { if (mat[i][j] != mat[i + j][0]) return false; } else { if (mat[i][j] != mat[i + j - n + 1][n - 1]) return false; } } } return true; } int main() { int n = 5; int mat[N][N] = { { 1, 2, 3, 4, 5}, { 2, 3, 4, 5, 6}, { 3, 4, 5, 6, 7}, { 4, 5, 6, 7, 8}, { 5, 6, 7, 8, 9} }; if(isHankelMat(mat, n)) cout << "This is Hankel Matrix"; else cout << "This is not Hankel Matrix"; }
Output
This is Hankel Matrix
- Related Articles
- Check if a given matrix is sparse or not in C++
- Check given matrix is magic square or not in C++
- Program to check if a matrix is Binary matrix or not in C++
- JavaScript program to check if a given matrix is sparse or not
- Check if a Matrix is Identity Matrix or not in Java?
- Check if a Matrix is Markov Matrix or not in Java
- C++ code to check given matrix is good or not
- Find if given matrix is Toeplitz or not in C++
- C Program to check if matrix is singular or not
- Check if a Matrix is Involutory or not in Java?
- Check if a given number is sparse or not in C++
- Check if a number is in given base or not in C++
- Check if a given array is pairwise sorted or not in C++
- Check if a given tree graph is linear or not in C++
- Program to check whether given matrix is Toeplitz Matrix or not in Python

Advertisements