Advertisement
InnaSibirova

Dinmix

Apr 12th, 2022
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                             Online C Compiler.
  4.                 Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include <stdlib.h>
  12. #include <malloc.h> // подключаем библиотеки
  13. int main()
  14. {  
  15.     srand(time(NULL));
  16.     int n = 20, k = 0;
  17.     int* mas1;
  18.     mas1 = (int*)malloc(n * sizeof(int)); // задаём массив a
  19.     int* mas2;
  20.     mas2 = (int*)malloc(n * sizeof(int)); // задаём массив b
  21.     int* c;
  22.     c = (int*)malloc(n * sizeof(int));    // задаём массив c
  23.     for(int i = 0; i < n; i++) {  // заполняе массивы a и b случайными числами и массив c в сулчае выполнения условия
  24.         mas1[i] = rand() % 100;
  25.         mas2[i] = rand() % 100;
  26.         if(mas1[i] > mas2[i]) {
  27.             c[k] = mas1[i];
  28.             k++;
  29.            
  30.         }
  31.        
  32.     }
  33.     for(int i = 0; i < n; i++) { // выводим массив a
  34.         printf("%d ", mas1[i]);
  35.     }
  36.     printf("\n");
  37.     for(int i = 0; i < n; i++) { // выводим массив b
  38.         printf("%d ", mas2[i]);
  39.     }
  40.     printf("\n");
  41.     for(int i = 0; i < k; i++) { // выводим массив c
  42.         printf("%d ", c[i]);
  43.     }
  44.     free(mas1);
  45.     free(mas2);
  46.     free(c);
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement