Advertisement
savovaap_

Untitled

May 15th, 2023
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. #define N 3
  5. #define M 4
  6.  
  7. bool checkRows(int matrix[N][M]) {
  8.     int i, j;
  9.     for (i = 0; i < N; i++) {
  10.         for (j = 0; j < M - 1; j++) {
  11.             if (matrix[i][j] > matrix[i][j + 1]) {
  12.                 return false;
  13.             }
  14.         }
  15.     }
  16.     return true;
  17. }
  18.  
  19. bool checkColumns(int matrix[N][M]) {
  20.     int i, j;
  21.     for (j = 0; j < M; j++) {
  22.         for (i = 0; i < N - 1; i++) {
  23.             if (matrix[i][j] < matrix[i + 1][j]) {
  24.                 return false;
  25.             }
  26.         }
  27.     }
  28.     return true;
  29. }
  30.  
  31. int main() {
  32.     int matrix[N][M] = {
  33.         {1, 2, 3, 4},
  34.         {5, 6, 7, 8},
  35.         {9, 10, 11, 12}
  36.     };
  37.  
  38.     bool rowsSorted = checkRows(matrix);
  39.     bool columnsSorted = checkColumns(matrix);
  40.  
  41.     if (rowsSorted && columnsSorted) {
  42.         printf("Матрицата отговаря на условието.\n");
  43.     } else {
  44.         printf("Матрицата НЕ отговаря на условието.\n");
  45.     }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement