c program using 2d array to check Indentity Matrix

c program using 2d array to check Indentity Matrix

  1. #include<stdio.h>
  2. int main()
  3. {
  4.  int array1[3][3],i,j,flag=0; 
  5.  for ( i = 0; i < 3; i++ ){ //related to row
  6.   for ( j = 0; j < 3; j++){ //related to column
  7.   
  8.     scanf("%d", &array1[i][j]) ;
  9.   }   
  10.  } 
  11.  /* output each array element's value */ 
  12.  for ( i = 0; i < 3; i++ ){ 
  13.   for ( j = 0; j < 3; j++ ){ 
  14.     printf(" %d\t ",array1[i][j] ); 
  15.   } 
  16.   printf("\n");
  17.  } 
  18.  for ( i = 0; i < 3; i++ ){ 
  19.   for ( j = 0; j < 3; j++ ){ 
  20.    if(array1[i][j] != 1 && array1[j][i] != 0 ) {
  21.      flag=1; break;
  22.    }
  23.   } 
  24.   printf("\n");
  25.  }
  26.  if(flag==0)
  27.    printf("It is an Identity Matrix.");
  28.  else
  29.    printf("It is not an Identity Matrix.");
  30.  return 0;

Output


//Entered matrix elements
1 0 0
0 1 0
0 0 1
//Displayed 3×3 Matrix
1 0 0
 0 1 0
  0 0 1
//Shown result
It is an Indentity Matrix 

choose next program from this list

Comments