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>
- using namespace std;
- int Vvod_chisel(char *);
- void Init(int *, int, char *);
- void Print(int *, int, char *);
- int * Search(int *A, int m, int *B, int n, int *newmas, int *size);
- int * Create(int value, int *newmas, int *size);
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "Russian");
- int n, m, *A, *B;
- do
- {
- m = Vvod_chisel("Введите размер первого массива = ");
- n = Vvod_chisel("Введите размер второго массива = ");
- } while (n <= 0 && m <= 0);
- A = new int[m];
- B = new int[n];
- int size = 0;
- int *newmas = new int[size];
- srand(time(NULL));
- Init(A, m, "Создание первого массива...");
- Init(B, n, "Создание второго массива...");
- Print(A, m, "Созданный первый массив");
- Print(B, n, "Созданный второй массив");
- cout << "Создание третьего массива..." << endl;
- newmas = Search(A, m, B, n, newmas, &size);
- Print(newmas, size, "Созданный третий массив");
- delete[]A;
- delete[]B;
- delete[]newmas;
- }
- int Vvod_chisel(char *ms)
- {
- cout << ms;
- char str[10];
- cin.getline(str, 10);
- return atoi(str);
- }
- void Init(int *mas, int n, char *ms)
- {
- cout << ms << endl;
- for (int i = 0; i < n; *mas++ = rand() % 30 + -10, i++);
- }
- void Print(int *mas, int n, char *ms)
- {
- cout << ms << endl;
- for (int i = 0; i < n; cout.width(3), cout << *mas++, i++);
- cout << endl;
- }
- int * Search(int *A, int m, int *B, int n, int *newmas, int *size)
- {
- for (int i = 0; i < m; i++)
- {
- if (*(A + i) >= 0)
- {
- newmas = Create(*(A + i), newmas, size);
- }
- }
- for (int i = 0; i < n; i++)
- {
- if (*(B + i) >= 0)
- {
- newmas = Create(*(B + i), newmas, size);
- }
- }
- return newmas;
- }
- int * Create(int value, int *newmas, int *size)
- {
- int *mas = new int[*size + 1];
- for (int i = 0; i < *size; i++)
- {
- *(mas + i) = *(newmas + i);
- }
- mas[*size] = value;
- *size += 1;
- return mas;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement