Advertisement
bercut312

Untitled

Feb 23rd, 2019
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <malloc.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. #include<stdio.h>
  6. #include<locale.h>
  7.  
  8. void main()
  9. {
  10. int chetArr;
  11. int *a; // указатель на массив 1
  12. int *b; // указатель на массив 2
  13. int *c;
  14. int n1,n2;
  15. int asw = 8;
  16. setlocale(0, "rus");
  17. printf("Введите размер первого массива: ");
  18. scanf("%d", &n1);
  19. printf("Введите размер второго массива: ");
  20. scanf("%d", &n2);
  21. system("cls");
  22. // Выделение памяти
  23. a = (int*)malloc(n1 * sizeof(int));
  24. b = (int*)malloc(n2 * sizeof(int));
  25. c = (int*)malloc((n1+n2) * sizeof(int));
  26. // Ввод элементов массива
  27. for (int i = 0; i<n1; i++)
  28. {
  29. printf("a[%d] = ", i);
  30. scanf("%d", &a[i]);
  31. }
  32. for (int i = 0; i<n2; i++)
  33. {
  34. printf("b[%d] = ", i);
  35. scanf("%d", &b[i]);
  36. }
  37. while (asw)
  38. {
  39.  
  40. printf("\n1.Объединение\n2.Пересечение\n3.Разность A/B\n4.Разность B/A\n");
  41. scanf("%d", &asw);
  42.  
  43. switch (asw)
  44. {
  45. case 0:
  46. exit;
  47. case 1:
  48. chetArr = 0;
  49. for (int i = 0; i < n1; i++)
  50. {
  51. int chet = 0;
  52. for (int j = 0; j < n2; j++)
  53. {
  54. if (a[i] != b[j])
  55. {
  56. chet++;
  57. }
  58. if ((a[i] != b[j]) && (chet == (n2)))
  59. {
  60. c[chetArr] = a[i];
  61. chetArr++;
  62. break;
  63. }
  64. if (a[i] == b[j])
  65. {
  66. c[chetArr] = a[i];
  67. chetArr++;
  68. break;
  69. }
  70. }
  71. }
  72.  
  73. for (int i = 0; i < n1; i++)
  74. {
  75. int chet = 0;
  76. for (int j = 0; j < n2; j++)
  77. {
  78.  
  79. if (b[i] != a[j])
  80. {
  81. chet++;
  82. }
  83. if ((b[i] != a[j]) && (chet == (n1)))
  84. {
  85. c[chetArr] = b[i];
  86. chetArr++;
  87. break;
  88. }
  89. }
  90. }
  91. for (int i = 0; i < chetArr; i++)
  92. {
  93. printf("%d ", c[i]);
  94. }
  95. printf("\n");
  96. break;
  97. case 2:
  98. chetArr = 0;
  99. for (int i = 0; i < n1; i++)
  100. {
  101. for (int j = 0; j < n2; j++)
  102. {
  103. if (a[i] == b[j])
  104. {
  105. c[chetArr] = a[i];
  106. chetArr++;
  107. break;
  108. }
  109. }
  110. }
  111. for (int i = 0; i < chetArr; i++)
  112. {
  113. printf("%d ", c[i]);
  114. }
  115. printf("\n");
  116. break;
  117. case 3:
  118. chetArr = 0;
  119. for (int i = 0; i < n1; i++)
  120. {
  121. int chet = 0;
  122. for (int j = 0; j < n2; j++)
  123. {
  124. if (a[i] != b[j])
  125. {
  126. ++chet;
  127. }
  128. if ((a[i] != b[j]) && (chet == (n2)))
  129. {
  130. c[chetArr] = a[i];
  131. chetArr++;
  132. break;
  133. }
  134. }
  135. }
  136.  
  137. for (int i = 0; i < chetArr; i++)
  138. {
  139. printf("%d ", c[i]);
  140. }
  141. printf("\n");
  142. break;
  143. case 4:
  144. chetArr = 0;
  145. for (int i = 0; i < n2; i++)
  146. {
  147. int chet = 0;
  148. for (int j = 0; j < n1; j++)
  149. {
  150. if (b[i] != a[j])
  151. {
  152. chet++;
  153. }
  154. if ((b[i] != a[j]) && (chet == (n1)))
  155. {
  156. c[chetArr] = b[i];
  157. chetArr++;
  158. break;
  159. }
  160. }
  161. }
  162.  
  163. for (int i = 0; i < chetArr; i++)
  164. {
  165. printf("%d ", c[i]);
  166. }
  167. printf("\n");
  168. break;
  169. case 5:
  170. break;
  171. default:
  172. break;
  173. }
  174. }
  175. // Вывод элементов массива
  176. free(c);
  177. getchar(); getchar();
  178. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement