Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "rus");
- const int N_MAX = 100;
- cout << "Порядок матрицы <= " << N_MAX << ". N = ";
- int N;
- cin >> N;
- if (N > N_MAX) N = N_MAX;
- else if (N < 0) N = 0;
- int A[N_MAX][N_MAX] = {};
- int B[N_MAX][N_MAX] = {};
- srand(static_cast<int>(time(0)));
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- A[i][j] = rand() % 101;
- int min_value;
- min_value = A[N - 1][N - 1];
- for (int k = 0; k < N; k++) {
- for (int i = N - 1, j = N - 1 - k; i >= 0, j < N; i--, j++) {
- B[i][j] = min_value;
- if (A[i][j] < min_value) {
- min_value = A[i][j];
- for (int i = N - 1, j = N - 1 - k; i >= 0, j < N; i--, j++)
- B[i][j] = min_value;
- }
- }
- }
- for (int k = 0; k < N; k++) {
- for (int i = N - 2 - k, j = 0; j < N - 1 - k, i >= 0; j++, i--) {
- B[i][j] = min_value;
- if (A[i][j] < min_value) {
- min_value = A[i][j];
- for (int i = N - 2 - k, j = 0; j < N - 1 - k, i >= 0; j++, i--) {
- B[i][j] = min_value;
- }
- }
- }
- }
- cout << setw(2 * N) << "Исходная матрица" << endl;
- for (int y = 0; y < N; y++) {
- for (int x = 0; x < N; x++) {
- cout << setw(4) << A[y][x];
- }
- cout << endl;
- }
- cout << setw(2 * N) << "Полученная матрица" << endl;
- for (int y = 0; y < N; y++) {
- for (int x = 0; x < N; x++) {
- cout << setw(4) << B[y][x];
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement