# Check if a given Matrix is an Identity Matrix with C

```
#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");
}
```

### Share this:

- Click to share on Twitter (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Google+ (Opens in new window)
- Click to share on WhatsApp (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Click to share on Skype (Opens in new window)
- Click to email this to a friend (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to share on LinkedIn (Opens in new window)
- Click to print (Opens in new window)