# Check Idempotent Matrix

“** Check Idempotent Matrix**” is a problem of matrix where we need to check whether given matrix is an idempotent matrix or not.

There are basically three different types of matrix:

: An identity matrix is a square matrix of size N*N which have all the diagonal element as 1 and others as 0.*Identity Matrix*: An Idempotent matrix is a matrix which is when multiplied by itself produces the same matrix.*Idempotent Matrix*: An involutory matrix is a matrix which when multiplied by itself gives identity matrix.*Involuntary Matrix*

Here, we are given a square matrix of size N*N. Our task is to check whether the given matrix is idempotent matrix or not.

**Example:**

N = 3 2 -2 -4 -1 3 4 1 -2 -3INPUT:Idempotent MatrixOUTPUT:

The solution of check idempotent matrix is to multiply the given matrix by itself and store the result in resultant matrix. If the resultant matrix is same as the given matrix, then given matrix is said to be idempotent. Else, it is not an idempotent matrix.

**C++ Program to check idempotent matrix is as follows:**

```
/* Program to check idempotent matrix */
#include<bits/stdc++.h>
using namespace std;
int main()
{
// Scan Dimension of the matrix
int n;
cout<<"Enter the dimesion of square matrix:\n";
cin>>n;
// Scan Elements of the matrix
int matrix[n][n];
cout<<"Enter the elements of square matrix:\n";
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
cin>>matrix[i][j];
// Initializing resultant matrix with 0
int resultant[n][n];
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
resultant[i][j] = 0;
//Multiply the matrix with itself and storing
// the result in resultant matrix
for (int i = 0 ; i < n ; i++)
{
for (int j = 0 ; j < n ; j++)
{
for (int k = 0 ; k < n ; k++)
{
resultant[i][j] += matrix[i][k] * matrix[k][j];
}
}
}
//Check whether the resultant matrix is
// equal to given matrix or not
bool result = true;
for (int i = 0 ; i < n ; i++)
{
for (int j = 0 ; j < n ; j++)
{
if(matrix[i][j] != resultant[i][j])
{
result = false;
break;
}
}
if(!result)
break;
}
if(result)
cout<<"Idempodent Matrix!!";
else
cout<<"Not Idempodent Matrix";
}
```

Enter the dimesion of square matrix: 3 Enter the elements of square matrix: 2 -2 -4 -1 3 4 1 -2 -3 Idempotent Matrix!!OUTPUT:

**Related Posts:**

- Program to check Involuntary Matrix.
- Program to print matrix in zig-zag order.
- Program to print matrix in spiral order.
- Program to sort a matrix.
- Program to Add two Matrix.
- Program to Transpose a Matrix.
- Program to Multiply Two Matrix.
- Program to check Identity Matrix.
- Find Most Frequent Character of the String.
- Check Anagram Strings.
- Check Whether Given String is Palindromic Anagram or Not.
- Check Whether Given String is Panagram or Not.
- Find First Non-Repeating Character of the String.
- Find Most Frequent Element of the Array.
- Find Pair in an Array with Given Sum.
- Find First Repeating Element of an Array.
- Find Majority Element of an Array.
- Program to check if String is isogram or not.
- Program to Reverse Each word of the String.
- Program to Print All the Substring of the Given String.