- /**
- *单位矩阵就是一个正方形矩阵,它除了主对角线的元素值为1以后,其余元素的值均为0
- */
- include <stdio.h>
- #define TRUE 1
- #define FALSE 0
- int is_identity_matrix( int matrix[10][10] );
- int main()
- {
- int result;
- int mat[10][10] = {
- {1,0,0,0,0,0,0,0,0,0},
- {0,1,0,0,0,0,0,0,0,0},
- {0,0,1,0,0,0,0,0,0,0},
- {0,0,0,1,0,0,0,0,0,0},
- {0,0,0,0,1,0,0,0,0,0},
- {0,0,0,0,0,1,0,0,0,0},
- {0,0,0,0,0,0,1,0,0,0},
- {0,0,0,0,0,0,0,1,0,0},
- {0,0,0,0,0,0,0,0,1,0},
- {0,0,0,0,0,0,0,0,0,1}
- };
- result = is_identity_matrix( mat );
- if( result )
- printf("mat is identity matrix\n");
- else
- printf("mat is not identity matrix\n");
- return 1;
- }
- int is_identity_matrix( int matrix[10][10])
- {
- int i , j ;
- int flags = 1;
- for( i = 0 ; i < 10 ; i++ )
- {
- for( j = 0 ; j < 10 ; j++ ){
- if( matrix[i][i] != 1 ){
- flags = 0;
- }
- if( i != j && matrix[i][j] != 0){
- flags = 0;
- }
- }
- }
- if( flags == 0 )
- return FALSE;
- else
- return TRUE;
- }
vim 7.3
gcc 版本 : 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)
system : Fedora 14