Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3a)
- /*
- * <summary> This function determines if a square matrix is descending diagonal </summary>
- * <params>
- "matrix" = The array containing the int elements
- "size" = Number of elements both row and column-wise
- </params>
- * <return> "1" : Is desc diagonal, "0": Otherwise </return>
- * <precond> "size" > 0 </precond>
- */
- int isDescDiagonal(int matrix[][MAX_SIZE], int size)
- {
- int row, col;
- for(row = 0; row < size; row++)
- {
- //Ignore row-0 col-0, it can be any value
- for(col = 1; col < size; col++)
- {
- //Diagonal
- if(row == col)
- {
- /* Not concurrently descending */
- if(matrix[row-1][col-1] - 1 != matrix[row][col])
- return 0;
- }
- /* If non-diagonal elements are not zero */
- else if(matrix[row][col] != 0)
- return 0;
- }
- }
- return 1;
- }
- 3b)
- /*
- * <summary> This function determines if a square matrix is anti-diagonal </summary>
- * <params>
- "matrix" = The array containing the int elements
- "size" = Number of elements both row and column-wise
- </params>
- * <return> "1" : Is anti diagonal, "0": Otherwise </return>
- * <precond> "size" > 0 </precond>
- */
- int isAntiDiagonal(int matrix[][MAX_SIZE], int size)
- {
- int row, col;
- for(row = 0; row < size; row++)
- {
- for(col = 0; col < size; col++)
- {
- //Diagonal
- if(row+col != size - 1)
- {
- /* If non-diagonal elements are not zero */
- if(matrix[row][col] !== 0)
- return 0;
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement