/*
* 单位矩阵(identity matrix)就是一个正方形矩阵,它除了主对角线的元素值为1
* 以后,其余元素的值均为 0。例如:
* 1 0 0
* 0 1 0
* 0 0 1
* 就是一个3*3的矩阵。编写一个名为 identity_matrix 的函数,它接受一个
* 10*10整型矩阵为参数,并返回一个布尔值,提升该矩阵是否为单位矩阵。
*/
/* This problem is simple because the argument must be a specific size. * The test for zero or one is simple, though perhaps not immediately obvious. */
/* Test a 10 by 10 matrix to see if it is an identity matrix */
#define FALSE 0 #define TRUE 1;
int identity_matrix( int matrix[10][10] ) { int row; int column;
/* Go through each of the matrix elements */
for( row=0; row<10; row++ ) { for( column=0; column<10; column++ ) { /* * If the row number is equal to the column number, * the value should be 1, else 0. */ if( matrix[row][column] != ( row == column ) ) // ??
return FALSE; } }
return TRUE; }
|
阅读(1244) | 评论(0) | 转发(0) |