/* 修改前一个问题的identity_matrix函数,他可以对数组进行扩展,
* 从而能够接受任意大小的矩阵参数。函数的第一个参数应该是一个整型
* 指针,你需要第二个参数用于指定矩阵的大小。
*/
/* * The storage order of the array elements allows a pointer to an * integer to be walked sequentially through the elements.Separate * counters keep track of the row and column, using the size argument * provided. Note that there is no way to check whether the matrix is * actually the size indicated by the second augrment. */
/* Test a square matrix to see if it is an identity matrix. */
#define FALSE 0 #define TRUE 1
int identity_matrix( int *matrix, int size ) { int row; int column;
/* Go through each of the matrix elements */ for( row=0; row<size; row+=1 ) { for( column=0; column<size; column+=1 ) { if( *matrix++ != ( row == column ) ) //?
return FALSE; } } return TRUE; }
|
阅读(1509) | 评论(0) | 转发(0) |