## Oct 3, 2011

### C Program to check if a given matrix is an identity matrix

C Program to check if a given matrix is an identity matrix or not. If I is theIdentity Matrix,then for any matrix A, IA=AI=A. Program will check the givan matrix is identity or not, and prints the appropriate message. Read more about C Programming Language .
-->
```/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
*                                  Happy Coding
***********************************************************/
/* C Program  Write a C Program to check if a given matrix is an identity matrix */
#include <stdio.h>

void main()
{
int A[10][10];
int i, j, R, C, flag =1;

printf("Enter the order of the matrix A\n");
scanf("%d %d", &R, &C);

printf("Enter the elements of matrix A\n");
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
scanf("%d",&A[i][j]);
}
}
printf("MATRIX A is\n");
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
printf("%3d",A[i][j]);
}
printf("\n");
}

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

for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
if((A[i][i] != 1) || (( i != j) && (A[i][j] != 0)))
{
flag = 0;
break;
}
}
}

if(flag == 1 )
printf("It is identity matrix\n");
else
printf("It is not a identity matrix\n");
}```
```Read more Similar C Programs
Matrix Programs
Learn C Programming```

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!