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.

Here is source code of the C program to check a given Matrix is an Identity Matrix. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C Program to check if a given matrix is an identity matrix`

`*/`

`#include <stdio.h>`

void main()

`{`

int a[10][10];

int i, 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 (i = 0; i < row; i++)

`{`

for (j = 0; j < column; j++)

`{`

scanf("%d", &a[i][j]);

`}`

`}`

printf("MATRIX A is \n");

for (i = 0; i < row; i++)

`{`

for (j = 0; j < column; j++)

`{`

printf("%3d", a[i][j]);

`}`

printf("\n");

`}`

`/* Check for unit (or identity) matrix */`

for (i = 0; i < row; i++)

`{`

for (j = 0; j < column; j++)

`{`

if (a[i][j] != 1 && a[j][i] != 0)

`{`

flag = 0;

break;

`}`

`}`

`}`

if (flag == 1 )

printf("It is identity matrix \n");

`else`

printf("It is not a identity matrix \n");

`}`

$ cc pgm58.c $ a.out Enter the order of the matrix A 3 3 Enter the elements of matrix A 1 2 3 5 1 8 6 4 1 MATRIX A is 1 2 3 5 1 8 6 4 1 It is not a identity matrix $ a.out Enter the order of the matrix A 3 3 Enter the elements of matrix A 1 0 0 0 1 0 0 0 1 MATRIX A is 1 0 0 0 1 0 0 0 1 It is identity matrix

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Matrix, go to C Programming Examples on Matrix. If you wish to look at programming examples on all topics, go to C Programming Examples.