Program to determine whether a given matrix is an identity matrix
Explanation
In this program, we need to check whether the given matrix is an identity matrix.
Identity Matrix
A matrix is said to be the identity matrix if it is the square matrix in which elements of principle diagonal are ones, and the rest of the elements are zeroes.
Algorithm
 Declare and initialize a twodimensional array a.
 Calculate the number of rows and columns present in the array and store it in variables rows and columns respectively.
 Initialize variable flag to true.
 Check if given matrix has the same number of rows and columns(square matrix).
 If not, print the error message "Matrix should be a square matrix."
 If given matrix is a square matrix then, loop through the array and check if all the elements of main diagonal are 1 and the rest of the elements are 0.
 If any of the condition is not satisfied, set the flag to false and break the loop.
 If the flag is equal to true which implies given matrix is an identity matrix.
 Else, given matrix is not an identity matrix.
Solution
Python
Output:
Given matrix is an identity matrix
C
Output:
Given matrix is an identity matrix
JAVA
Output:
Given matrix is an identity matrix
C#
Output:
Given matrix is an identity matrix
PHP
Output:
Given matrix is an identity matrix
