/*
* 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;
}
|