Advertisement
semenrbt

2.2static

Feb 18th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 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.   if(N <= M)
  12.   {
  13.     int Z[N] = {0};
  14.     for(int i = 0; i < N; i++)
  15.     {
  16.       for(int j = 0; j < M; j++)
  17.       {
  18.         if(x[i] == y[j]) s++;
  19.       }
  20.       if(s == 1)
  21.       {
  22.         Z[counter] = x[i];
  23.         counter++;
  24.       }
  25.       if(s > 1)
  26.       {
  27.         printf("Elementi povtoryayutsya\n");
  28.         return 0;
  29.       }
  30.       s = 0;
  31.     }
  32.     printf("Z[%d] = {", counter);
  33.     for(int k = 0; k < counter; k++)
  34.       printf("%d, ", Z[k]);
  35.     printf("};\n");
  36.   }
  37.   else
  38.   {
  39.     int Z[M];
  40.     for(int i = 0; i < N; i++)
  41.     {
  42.       for(int j = 0; j < M; j++)
  43.       {
  44.         if(x[i] == y[j]) s++;
  45.       }
  46.       if(s == 1)
  47.       {
  48.         Z[counter] = x[i];
  49.         counter++;
  50.       }
  51.       if(s > 1)
  52.       {
  53.         printf("Elementi povtoryayutsya\n");
  54.         return 0;
  55.       }
  56.       s = 0;
  57.     }
  58.     printf("Z[%d] = {", counter);
  59.     for(int k = 0; k < counter; k++)
  60.       printf("%d, ", Z[k]);
  61.     printf("};\n");
  62.   }
  63.  
  64.  
  65.  
  66.   return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement