Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- template <typename TYPE>
- TYPE **newMas(size_t x, size_t y, TYPE flag);
- template <typename TYPE>
- void delMas(TYPE **mas, size_t x);
- template <typename TYPE>
- void masRand(TYPE **mas, size_t x, size_t y);
- template <typename TYPE>
- void coutMas(TYPE **mas, size_t x, size_t y);
- int main()
- {
- srand(time(NULL));
- setlocale(0, "");
- cout << "Введите размеры массивов" << endl;
- size_t x, y;
- cin >> x;
- cin >> y;
- int **mas1 = newMas(x, y, (int)1);
- int **mas2 = newMas(x, y, (int)1);
- int **minMas = newMas(x, y, (int)1);
- int **maxMas = newMas(x, y, (int)1);
- masRand(mas1, x, y);
- masRand(mas2, x, y);
- cout << endl << "Первый массив:" << endl;
- coutMas(mas1, x, y);
- cout << endl << "Второй массив:" << endl;
- coutMas(mas2, x, y);
- for (size_t i = 0; i < x; i++)
- for (size_t j = 0; j < y; j++)
- {
- if (mas1[i][j] < mas2[i][j])
- {
- minMas[i][j] = mas1[i][j];
- maxMas[i][j] = mas2[i][j];
- }
- else
- {
- minMas[i][j] = mas2[i][j];
- maxMas[i][j] = mas1[i][j];
- }
- if (mas1[i][j] == mas2[i][j])
- maxMas[i][j] = minMas[i][j] = mas1[i][j];
- }
- cout << endl << "Массив максимальных чисел:" << endl;
- coutMas(maxMas, x, y);
- cout << endl << "Массив минимальных чисел:" << endl;
- coutMas(minMas, x, y);
- delMas(mas1, x);
- delMas(mas2, x);
- delMas(minMas, x);
- delMas(maxMas, x);
- return 0;
- }
- template <typename TYPE>
- TYPE **newMas(size_t x, size_t y, TYPE flag)
- {
- TYPE **mas = new TYPE *[x];
- for (size_t i = 0; i < x; i++)
- mas[i] = new TYPE [y];
- return mas;
- }
- template <typename TYPE>
- void delMas(TYPE **mas, size_t x)
- {
- for (size_t i = 0; i < x; i++)
- delete mas[i];
- delete[]mas;
- }
- template <typename TYPE>
- void masRand(TYPE **mas, size_t x, size_t y)
- {
- for (size_t i = 0; i < x; i++)
- for (size_t j = 0; j < y; j++)
- mas[i][j] = rand() % 51 - 25;
- }
- template <typename TYPE>
- void coutMas(TYPE **mas, size_t x, size_t y)
- {
- for (size_t i = 0; i < x; i++)
- {
- for (size_t j = 0; j < y; j++)
- cout << mas[i][j] << "\t";
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement