Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int *CreateArray(int N, int min, int max){
- if(N < 0) return NULL;
- int *mas = NULL;
- if(max < min)
- {
- int s = min;
- min = max;
- max = s;
- }
- mas = (int*) malloc(sizeof(int)*N);
- if(mas == NULL) return NULL;
- for(int k = 0; k < N; k++)
- mas[k] = rand()%(max - min + 1) + min;
- return mas;
- }
- int main()
- {
- srand(time(NULL));
- const int N = rand()%10 + 1;
- const int M = rand()%10 + 1;
- int * x = CreateArray(N, 0, 15);
- int * y = CreateArray(M, 0, 15);
- if(x == NULL){
- printf("Error.\n");
- return 0;
- }
- if(y == NULL){
- printf("Error.\n");
- return 0;
- }
- int s = 0, counter = 0;
- int K = 0;
- if(N <= M) K = N;
- else K = M;
- int Z[K];
- 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");
- free(x);
- free(y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement