c program using 2d array to check Indentity Matrix
- #include<stdio.h>
- int main()
- {
- int array1[3][3],i,j,flag=0;
- for ( i = 0; i < 3; i++ ){ //related to row
- for ( j = 0; j < 3; j++){ //related to column
- scanf("%d", &array1[i][j]) ;
- }
- }
- /* output each array element's value */
- for ( i = 0; i < 3; i++ ){
- for ( j = 0; j < 3; j++ ){
- printf(" %d\t ",array1[i][j] );
- }
- printf("\n");
- }
- for ( i = 0; i < 3; i++ ){
- for ( j = 0; j < 3; j++ ){
- if(array1[i][j] != 1 && array1[j][i] != 0 ) {
- flag=1; break;
- }
- }
- printf("\n");
- }
- if(flag==0)
- printf("It is an Identity Matrix.");
- else
- printf("It is not an Identity Matrix.");
- 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
Comments