Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <time.h>
- #include <stdlib.h>
- #include <conio.h>
- using namespace std;
- void Init1(int *mas, int size1);
- void Init2(int *arr, int size2);
- void Print(int *mas, int size1, int *arr, int size2);
- void Funk(int *mas, int size1, int *arr, int size2);
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "Russian");
- srand(time(NULL));
- int size1 = rand() % 10 + 2;
- int size2 = rand() % 10 + 2;
- int *mas = new int[size1];
- int *arr = new int[size2];
- Init1(mas, size1);
- Init2(arr, size2);
- for (;;)
- {
- system("cls");
- Print(mas, size1, arr, size2);
- cout << "1. Сравнить массивы по содержанию" << endl;
- cout << "2. Сравнить массивы по длине" << endl;
- cout << "3. Обновить массивы" << endl;
- cout << "4. Выход" << endl;
- int v;
- cin >> v;
- switch (v)
- {
- case 1:
- Funk(mas, size1, arr, size2);
- _getch();
- break;
- case 2:
- if (size1 == size2)
- {
- cout << "Массивы равны" << endl;
- }
- else
- {
- cout << "Массивы не равны" << endl;
- }
- _getch();
- break;
- case 3:
- size1 = rand() % 10 + 2;
- size2 = rand() % 10 + 2;
- Init1(mas, size1);
- Init2(arr, size2);
- break;
- case 4:
- exit(0);
- default: break;
- }
- }
- delete[]mas;
- delete[]arr;
- }
- void Init1(int *mas, int size1)
- {
- for (int i = 0; i < size1; i++)
- {
- mas[i] = rand() % 30;
- }
- }
- void Init2(int *arr, int size2)
- {
- for (int i = 0; i < size2; i++)
- {
- arr[i] = rand() % 30;
- }
- }
- void Print(int *mas, int size1, int *arr, int size2)
- {
- cout << "Массив №1" << endl;
- for (int i = 0; i < size1; i++)
- {
- cout.width(4);
- cout << mas[i];
- }
- cout << endl;
- cout << "Массив №2" << endl;
- for (int i = 0; i < size2; i++)
- {
- cout.width(4);
- cout << arr[i];
- }
- cout << endl;
- }
- void Funk(int *mas, int size1, int *arr, int size2)
- {
- int count = 0;
- for (int i = 0; i < size1; i++)
- {
- for (int j = 0; j < size2; j++)
- {
- if (mas[i] == arr[j])
- {
- count++;
- break;
- }
- }
- }
- if (count == size1 || count == size2)
- {
- cout << "Массивы равны" << endl;
- }
- else
- {
- cout << "Массивы не равны" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement