Advertisement
STANAANDREY

tp8-10

Feb 21st, 2023 (edited)
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <errno.h>
  5. //#define calloc(...) NULL; errno = ENOMEM;
  6. #define COLS 4
  7.  
  8. void checkAlloc(void *p) {
  9.   if (p == NULL) {
  10.     perror("alloc err");
  11.     exit(EXIT_FAILURE);
  12.   }
  13. }
  14.  
  15. int main(void) {
  16.   int n;
  17.   scanf("%d", &n);
  18.   int (*arr)[COLS] = NULL;
  19.   arr = calloc(sizeof(int[COLS]), n);
  20.   checkAlloc(arr);
  21.  
  22.   for (int i = 0; i < n; i++) {
  23.     for (int j = 0; j < COLS; j++) {
  24.       scanf("%d", &arr[i][j]);
  25.     }
  26.   }
  27.  
  28.   printf("ascendent rows: ");
  29.   for (int i = 0; i < n; i++) {
  30.     bool ok = true;
  31.     for (int j = 1; j < COLS; j++) {
  32.       ok &= arr[i][j - 1] < arr[i][j];
  33.     }
  34.     if (ok) {
  35.       printf("%d ", i);
  36.     }
  37.   }
  38.   puts("");
  39.   free(arr);
  40.   return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement