# Check Involuntary Matrix

“** Check Involuntary Matrix**” is a basic problem of matrix where we need to check whether given matrix is an involuntary 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 involuntary matrix or not.

**Example:**

N=3 1 0 0 0 -1 0 0 0 -1INPUT:Involutory Matrix!!OUTPUT:

The solution to check involuntary matrix is to multiply the given matrix by itself and store the result in resultant matrix. If the resultant matrix identity matrix, then given matrix is said to be involutory matrix. Else, it is not an involutory matrix.

**C++ Program to Check Involuntary Matrix is as follows:**

```
/* Program to Check Involuntary 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
// involuntary matrix or not
bool result = true;
for (int i = 0 ; i < n ; i++)
{
for (int j = 0 ; j < n ; j++)
{
if(i==j && resultant[i][j]!=1)
{
result = false;
break;
}
else if(i!=j && resultant[i][j]!=0)
{
result = false;
break;
}
}
if(!result)
break;
}
if(result)
cout<<"Involutory Matrix!!";
else
cout<<"Not Involutory Matrix";
}
```

Enter the dimesion of square matrix: 3 Enter the elements of square matrix: 1 0 0 0 -1 0 0 0 -1 Involutory Matrix!!OUTPUT:

**Related Posts:**

- Program to check Identity Matrix.
- Program to check Idempotent 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 Reverse a String.
- Program to Count Number of Characters in a String.
- Program to Count frequency of particular character of the String.
- Program to Count Number of Vowels and Number of Consonants in a String.
- Program to Check if String is alphabetic or numeric or alpha-numeric.
- Program to copy One Character Array to Another.
- Program to Concatenate Two Character Arrays.
- Program to Check whether given String is Palindrome or not.
- Program to convert lower-case alphabet to upper-case alphabet and vice-versa.
- Program to count total number of words in a string.
- Program to find smallest and largest word of the String.
- Program to find Most Frequent Character of the String.