Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <malloc.h>
- #include<stdlib.h>
- #include<math.h>
- #include<stdio.h>
- #include<locale.h>
- void main()
- {
- int chetArr;
- int *a; // указатель на массив 1
- int *b; // указатель на массив 2
- int *c;
- int n1,n2;
- int asw = 8;
- setlocale(0, "rus");
- printf("Введите размер первого массива: ");
- scanf("%d", &n1);
- printf("Введите размер второго массива: ");
- scanf("%d", &n2);
- system("cls");
- // Выделение памяти
- a = (int*)malloc(n1 * sizeof(int));
- b = (int*)malloc(n2 * sizeof(int));
- c = (int*)malloc((n1+n2) * sizeof(int));
- // Ввод элементов массива
- for (int i = 0; i<n1; i++)
- {
- printf("a[%d] = ", i);
- scanf("%d", &a[i]);
- }
- for (int i = 0; i<n2; i++)
- {
- printf("b[%d] = ", i);
- scanf("%d", &b[i]);
- }
- while (asw)
- {
- printf("\n1.Объединение\n2.Пересечение\n3.Разность A/B\n4.Разность B/A\n");
- scanf("%d", &asw);
- switch (asw)
- {
- case 0:
- exit;
- case 1:
- chetArr = 0;
- for (int i = 0; i < n1; i++)
- {
- int chet = 0;
- for (int j = 0; j < n2; j++)
- {
- if (a[i] != b[j])
- {
- chet++;
- }
- if ((a[i] != b[j]) && (chet == (n2)))
- {
- c[chetArr] = a[i];
- chetArr++;
- break;
- }
- if (a[i] == b[j])
- {
- c[chetArr] = a[i];
- chetArr++;
- break;
- }
- }
- }
- for (int i = 0; i < n1; i++)
- {
- int chet = 0;
- for (int j = 0; j < n2; j++)
- {
- if (b[i] != a[j])
- {
- chet++;
- }
- if ((b[i] != a[j]) && (chet == (n1)))
- {
- c[chetArr] = b[i];
- chetArr++;
- break;
- }
- }
- }
- for (int i = 0; i < chetArr; i++)
- {
- printf("%d ", c[i]);
- }
- printf("\n");
- break;
- case 2:
- chetArr = 0;
- for (int i = 0; i < n1; i++)
- {
- for (int j = 0; j < n2; j++)
- {
- if (a[i] == b[j])
- {
- c[chetArr] = a[i];
- chetArr++;
- break;
- }
- }
- }
- for (int i = 0; i < chetArr; i++)
- {
- printf("%d ", c[i]);
- }
- printf("\n");
- break;
- case 3:
- chetArr = 0;
- for (int i = 0; i < n1; i++)
- {
- int chet = 0;
- for (int j = 0; j < n2; j++)
- {
- if (a[i] != b[j])
- {
- ++chet;
- }
- if ((a[i] != b[j]) && (chet == (n2)))
- {
- c[chetArr] = a[i];
- chetArr++;
- break;
- }
- }
- }
- for (int i = 0; i < chetArr; i++)
- {
- printf("%d ", c[i]);
- }
- printf("\n");
- break;
- case 4:
- chetArr = 0;
- for (int i = 0; i < n2; i++)
- {
- int chet = 0;
- for (int j = 0; j < n1; j++)
- {
- if (b[i] != a[j])
- {
- chet++;
- }
- if ((b[i] != a[j]) && (chet == (n1)))
- {
- c[chetArr] = b[i];
- chetArr++;
- break;
- }
- }
- }
- for (int i = 0; i < chetArr; i++)
- {
- printf("%d ", c[i]);
- }
- printf("\n");
- break;
- case 5:
- break;
- default:
- break;
- }
- }
- // Вывод элементов массива
- free(c);
- getchar(); getchar();
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement