# Check Identity Matrix

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

*Example:*

1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1INPUT:TRUEOUTPUT:

**C++ Program to check Identity Matrix is as follows:**

#include<bits/stdc++.h> using namespace std; int main() { int N; // Scan Dimensions of the matrix cout<<"Enter the dimension of the matrix:\n"; cin>>N; int matrix[N][N]; // Scan Matrix Elements cout<<"Enter the elements of the matrix:\n"; for(int i = 0 ; i < N ; i++) for(int j = 0 ; j < N ; j++) cin>>matrix[i][j]; bool result = true; // Check Identity matrix for(int i = 0 ; i < N ; i++) { for(int j = 0 ; j < N ; j++) { if(i==j && matrix[i][j]!=1) { result = false; break; } else if(i!=j && matrix[i][j]!=0) { result = false; break; } } if(!result) break; } // Print the result if(result) cout<<"The Matrix is Identity Matrix"; else cout<<"The Matrix is not Identity Matrix"; }

Enter the dimension of the matrix: 3 Enter the elements of the matrix: 1 0 0 0 1 0 0 0 1 The Matrix is Identity MatrixOUTPUT:

**Related Posts:**

**Program to check Idempotent Matrix.****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 Rotate Array Elements by ‘D’ positions.****Program to find most frequent element in an array.****Program to find pair in an array with given sum.****Program to find first repeating element of an array.****Program to merge two sorted arrays.****Program to find missing number in an array.****Program to sort if array is sorted.****Program to print Alternate Elements of an Array.****Program to swap kth element from beginning to kth element from end in an Array.****Program to print all possible subarrays of the given array.****Program to print kth smallest and kth largest element of an Array.****Program to find equilibrium index of an Array.**