#include <stdio.h>
#include <stdbool.h>
#define COLS 4
bool isSquareMatrix(int matrix[][COLS], int rows, int cols) {
// Check if the matrix is empty
if (rows == 0 || cols == 0) {
return false; // An empty matrix is not a square matrix
}
// Check if the number of rows equals the number of columns
return rows == cols;
}
int main() {
// Initialize the matrix
int matrix[][COLS] = {
{5, 8, 9, 10},
{1, 4, 6, 13},
{7, 3, 0, 18},
{6, 8, 9, 20}
};
// Calculate the total size of the matrix in bytes
size_t totalSize = sizeof(matrix);
// Calculate the size of one row
size_t rowSize = sizeof(matrix[0]);
// Calculate the number of rows and columns
size_t rows = totalSize / rowSize;
if (isSquareMatrix(matrix, rows, COLS)) {
printf("The matrix is a square matrix.\n");
} else {
printf("The matrix is not a square matrix.\n");
}
return 0;
}
/*
run:
The matrix is not a square matrix.
*/