Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #define N 3
- #define M 4
- bool checkRows(int matrix[N][M]) {
- int i, j;
- for (i = 0; i < N; i++) {
- for (j = 0; j < M - 1; j++) {
- if (matrix[i][j] > matrix[i][j + 1]) {
- return false;
- }
- }
- }
- return true;
- }
- bool checkColumns(int matrix[N][M]) {
- int i, j;
- for (j = 0; j < M; j++) {
- for (i = 0; i < N - 1; i++) {
- if (matrix[i][j] < matrix[i + 1][j]) {
- return false;
- }
- }
- }
- return true;
- }
- int main() {
- int matrix[N][M] = {
- {1, 2, 3, 4},
- {5, 6, 7, 8},
- {9, 10, 11, 12}
- };
- bool rowsSorted = checkRows(matrix);
- bool columnsSorted = checkColumns(matrix);
- if (rowsSorted && columnsSorted) {
- printf("Матрицата отговаря на условието.\n");
- } else {
- printf("Матрицата НЕ отговаря на условието.\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement