"C and Pointers" chapter 8th programming Exercises 3rd:
1 /*2 * * Determine if a 10*10 matrix is a unit matrix3 */4 5#include <stdio.h>6 #defineROW 107 #defineCOL 108 9 /*Ten * * Function accepts a matrix of 10*10 One * * Determine if it is a unit matrix A * * return value: - * * is the unit matrix, returns 1 - * * Not a unit matrix, return 0 the */ - int -Indentity_matrix (int(*matrix) [Ten] ) - { + intRow, col; - for(row =0; Row < row; ++row) + for(col =0; Col < Col; ++Col) A { at //If a number that is not 1 appears on the diagonal, 0 is returned - if(col = = row && Matrix[row][col]! =1 ) - return 0; - //returns 0 if the rest of the positions appear not 0 - if(Col! = row && Matrix[row][col]! =0 ) - return 0; in /* - * * The above two if statements can be combined into the following form: to * * IF (matrix[row] [col]! = (Row = = col)) + * * return 0; - */ the } * $ //To be able to perform here, the description is the unit matrix, which returns 1Panax Notoginseng return 1; - } the + int A Main () the { + intM[row][col]; - intI, J; $ $ for(i =0; i < ROW; ++i) - for(j =0; J < COL; ++j) -scanf"%d", * (M + i) +j); the -printf"%d", Indentity_matrix (m));Wuyi the return 0; -}
Determines whether a 10*10 matrix is a unit matrix