Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 7
- #define M 4
- int main()
- {
- int x[N] = {1, 2, 3, 4, 5, 6, 7}; // По условию, элементы массивов не повторяются
- int y[M] = {6, 2, 8, 4};
- int s = 0, counter = 0;
- if(N <= M)
- {
- int Z[N] = {0};
- for(int i = 0; i < N; i++)
- {
- for(int j = 0; j < M; j++)
- {
- if(x[i] == y[j]) s++;
- }
- if(s == 1)
- {
- Z[counter] = x[i];
- counter++;
- }
- if(s > 1)
- {
- printf("Elementi povtoryayutsya\n");
- return 0;
- }
- s = 0;
- }
- printf("Z[%d] = {", counter);
- for(int k = 0; k < counter; k++)
- printf("%d, ", Z[k]);
- printf("};\n");
- }
- else
- {
- int Z[M];
- for(int i = 0; i < N; i++)
- {
- for(int j = 0; j < M; j++)
- {
- if(x[i] == y[j]) s++;
- }
- if(s == 1)
- {
- Z[counter] = x[i];
- counter++;
- }
- if(s > 1)
- {
- printf("Elementi povtoryayutsya\n");
- return 0;
- }
- s = 0;
- }
- printf("Z[%d] = {", counter);
- for(int k = 0; k < counter; k++)
- printf("%d, ", Z[k]);
- printf("};\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement