Advertisement
semenrbt

2.2 v v29419394

Feb 19th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 7
  4. #define M 4
  5.  
  6. int main()
  7. {
  8.   int x[N] = {1, 2, 3, 4, 5, 6, 7}; // По условию, элементы массивов не повторяются
  9.   int y[M] = {6, 2, 8, 4};
  10.   int s = 0, counter = 0;
  11.   int K = 0;
  12.   if(N <= M) K = N;
  13.   else K = M;
  14.  
  15.   int Z[K];
  16.     for(int i = 0; i < N; i++)
  17.     {
  18.       for(int j = 0; j < M; j++)
  19.       {
  20.         if(x[i] == y[j]) s++;
  21.       }
  22.       if(s == 1)
  23.       {
  24.         Z[counter] = x[i];
  25.         counter++;
  26.       }
  27.       if(s > 1)
  28.       {
  29.         printf("Elementi povtoryayutsya\n");
  30.         return 0;
  31.       }
  32.       s = 0;
  33.     }
  34.     printf("Z[%d] = {", counter);
  35.     for(int k = 0; k < counter; k++)
  36.       printf("%d, ", Z[k]);
  37.     printf("};\n");
  38.  
  39.  
  40.  
  41.  
  42.   return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement