C Programming Code Examples C > Arrays and Matrices Code Examples Program to Check if a given Matrix is an Identity Matrix Program to Check if a given Matrix is an Identity Matrix This C Program checks a given Matrix is an Identity Matrix. Identity matrix is a square matrix with 1's along the diagonal from upper left to lower right and 0's in all other positions. If it satisfies the structure as explained before then the matrix is called as identity matrix. #include <stdio.h> void main() { int a[25][25]; int x, j, row, column, flag = 1; printf("Enter the order of the matrix A \n"); scanf("%d %d", &row, &column); printf("Enter the elements of matrix A \n"); for (x = 0; x < row; x++) { for (j = 0; j < column; j++) { scanf("%d", &a[x][j]); } } printf("MATRIX A is \n"); for (x = 0; x < row; x++) { for (j = 0; j < column; j++) { printf("%3d", a[x][j]); } printf("\n"); } /* Check for unit (or identity) matrix */ for (x = 0; x < row; x++) { for (j = 0; j < column; j++) { if (a[x][j] != 1 && a[j][x] != 0) { flag = 0; break; } } } if (flag == 1 ) printf("It is identity matrix \n"); else printf("It is not a identity matrix \n"); }