Б А Б У Р О В И В А Н
-----------------------------------------------------------------------------------
-----------
-----------------------------------------------------------------------------------
-----------
З А Д А Н И Е 1
int main()
{
setlocale(LC_ALL, "Russian");
int min = -2, max = 2;
cout << "Введите минимальное значение элемента массива: ";
cin >> min;
cout << "Минимальное принято: " << min << endl;
cout << "Введите максимальное значение элемента массива: ";
cin >> max;
cout << "Максимальное принято: " << max << endl;
int size1 = 6, size2 = 6;
cout << "Введите размер 1-го массива: ";
cin >> size1;
cout << "Введите размер 2-го массива: ";
cin >> size2;
srand(time(0));
int* arr1, * arr2;
arr1 = new int[size1];
arr2 = new int[size2];
if (arr1 == nullptr || arr2 == nullptr)
{
cout << "Не удалось создать массивы";
return 1;
}
for (int* p1 = arr1; p1 - arr1 < size1; p1++)
*p1 = rand() % (max - min + 1) + min;
for (int* p2 = arr2; p2 - arr2 < size2; p2++)
*p2 = rand() % (max - min + 1) + min;
int* p3 = arr3;
for (int* p1 = arr1, *p2 = arr2; p1 < arr1 + size1 && p2 < arr2 + size2; )
{
if (*p1 < *p2)
{
p1++;
continue;
}
else if (*p1 > *p2)
{
p2++;
continue;
}
else
{
*p3 = *p1;
do
p1++;
while (*p1 == *p3);
p3++;
}
}
cout << "Количество общих элементов: " << size3 << endl << "Сам массив 3:";
for (int* p3 = arr3; p3 - arr3 < size3; p3++)
cout << " " << *p3;
system("pause");
return 0;
}
-----------------------------------------------------------------------------------
-----------
-----------------------------------------------------------------------------------
-----------
З А Д А Н И Е 2
int main()
{
setlocale(LC_CTYPE, "rus");
int* a = 0, * b = 0, * c = 0, * res, * buf;
int m = 0, n = 0, k = 0, index = 0;
cout << "Введите числа m и n (разделённые пробелом): ";
cin >> m >> n;
a = new int[m]; b = new int[n];
c = new int[m + n];
cout << "\n a[j]";
for (int j = 0; j < m; j++)
{
a[j] = (int)((((float)rand() / (float)RAND_MAX) * 10) + 0);
cout << "\n" << a[j] << endl;
}
cout << "\n b[j]";
for (int j = 0; j < n; j++)
{
b[j] = (int)((((float)rand() / (float)RAND_MAX) * 10) + 0);
cout << "\n " << b[j] << endl;
}
for (int i = 0; i < m; i++)
{
k = 0;
for (int j = 0; j < n; j++)
{
delete[]c;
res = new int[buf1 + 1]; cout << "\nres[i]= ";
for (int i = 0; i <= buf1; i++)
{
res[i] = buf[i];
cout << "\n" << res[i];
}
delete[]buf; delete[]res;
return 0;
}
-----------------------------------------------------------------------------------
-----------