C++ Program to check idempotent matrix Last Updated : 29 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Given N * N matrix and the task is to check matrix is an idempotent matrix or not.Idempotent matrix: A matrix is said to be an idempotent matrix if the matrix multiplied by itself returns the same matrix. The matrix M is said to be an idempotent matrix if and only if M * M = M. In an idempotent matrix M is a square matrix. Examples: Input : mat[][] = {{3, -6}, {1, -2}}; Output : Idempotent Matrix Input : mat[N][N] = {{2, -2, -4}, {-1, 3, 4}, {1, -2, -3}} Output : Idempotent Matrix. C++ // Program to check given matrix // is idempotent matrix or not. #include<bits/stdc++.h> #define N 3 using namespace std; // Function for matrix multiplication. void multiply(int mat[][N], int res[][N]) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { res[i][j] = 0; for (int k = 0; k < N; k++) res[i][j] += mat[i][k] * mat[k][j]; } } } // Function to check idempotent // property of matrix. bool checkIdempotent(int mat[][N]) { // Calculate multiplication of matrix // with itself and store it into res. int res[N][N]; multiply(mat, res); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (mat[i][j] != res[i][j]) return false; return true; } // Driver function. int main() { int mat[N][N] = {{2, -2, -4}, {-1, 3, 4}, {1, -2, -3}}; // checkIdempotent function call. if (checkIdempotent(mat)) cout << "Idempotent Matrix"; else cout << "Not Idempotent Matrix."; return 0; } OutputIdempotent Matrix Time Complexity: O(N3)Auxiliary Space: O(N2) Please refer complete article on Program to check idempotent matrix for more details! Comment More infoAdvertise with us Next Article C++ Program to check idempotent matrix kartik Follow Improve Article Tags : Matrix C++ Programs C++ DSA Practice Tags : CPPMatrix Similar Reads C++ Program to check Involutory Matrix Given a matrix and the task is to check matrix is an involutory matrix or not. Involutory Matrix: A matrix is said to be an involutory matrix if matrix multiply by itself returns the identity matrix. The involutory matrix is the matrix that is its own inverse. The matrix A is said to be an involutor 2 min read C++ Program for Identity Matrix Introduction to Identity Matrix : The dictionary definition of an Identity Matrix is a square matrix in which all the elements of the principal or main diagonal are 1's and all other elements are zeros. In the below image, every matrix is an Identity Matrix. In linear algebra, this is sometimes call 3 min read C++ Program To Check if Two Matrices are Identical The below program checks if two square matrices of size 4*4 are identical or not. For any two matrices to be equal, the number of rows and columns in both the matrix should be equal and the corresponding elements should also be equal. Recommended: Please solve it on "PRACTICE" first, before moving 2 min read C++ Program to check if matrix is lower triangular Given a square matrix and the task is to check the matrix is in lower triangular form or not. A square matrix is called lower triangular if all the entries above the main diagonal are zero. Examples: Input : mat[4][4] = {{1, 0, 0, 0}, {1, 4, 0, 0}, {4, 6, 2, 0}, {0, 4, 7, 6}}; Output : Matrix is in 2 min read C++ Program to check if a matrix is symmetric A square matrix is said to be symmetric matrix if the transpose of the matrix is same as the given matrix. Symmetric matrix can be obtain by changing row to column and column to row. Examples: Input : 1 2 3 2 1 4 3 4 3 Output : Yes Input : 3 5 8 3 4 7 8 5 3 Output : No A Simple solution is to do fo 3 min read Like