Friday, February 5, 2016

C program to check Identity 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
printf("Element:");
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;
}

No comments:

Post a Comment