Advertisement
xotohop

Tima1

Dec 26th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. #define RAND(a,b) (a + rand() % (b - a))
  6.  
  7. int main()
  8. {
  9.     srand(time(NULL));
  10.     int n, m, i, j, count, size;
  11.     int **x, *y;
  12.  
  13.     printf("N = ");
  14.     scanf("%d", &n);
  15.     printf("M = ");
  16.     scanf("%d", &m);
  17.    
  18.     x = (int **)malloc(n*sizeof(int *));
  19.     for (i = 0; i < n; i++)
  20.         x[i] = (int *)malloc(m*sizeof(int));
  21.  
  22.     for (i = 0; i < n; i++)
  23.     {
  24.         for (j = 0; j < m; j++)
  25.         {
  26.             x[i][j] = RAND(-9, 9);
  27.             printf("%d ", x[i][j]);
  28.             if (x[i][j] < 0)
  29.                 count++;
  30.         }
  31.         printf("\n");
  32.     }
  33.    
  34.     y = (int *)malloc(count*sizeof(int));
  35.    
  36.     count = 0;
  37.     for (i = 0; i < n; i++)
  38.     {
  39.         for (j = 0; j < m; j++)
  40.         {  
  41.             if (x[i][j] < 0)
  42.             {
  43.                 y[count] = x[i][j];
  44.                 count++;
  45.             }
  46.         }
  47.     }
  48.  
  49.     for (i = 0; i < count; i++)    
  50.         printf("%d ", y[i]);
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement